Created
February 8, 2013 04:57
-
-
Save rvowles/4736689 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.bluetrainsoftware.vertx | |
import org.vertx.java.deploy.Verticle | |
import org.vertx.java.deploy.impl.VerticleFactory | |
import org.vertx.java.deploy.impl.VerticleManager | |
class SpringVerticleFactory implements VerticleFactory { | |
private VerticleManager mgr | |
@Override | |
void init(VerticleManager manager) { | |
mgr = manager | |
} | |
@Override | |
Verticle createVerticle(String main, ClassLoader parentCL) throws Exception { | |
Class clazz = parentCL.loadClass("org.springframework.context.support.ClassPathXmlApplicationContext") | |
String xmlFile = main.substring(0, main.length() - ".spring".length()).replace('.', '/') + ".xml" | |
if (!xmlFile.startsWith("/")) | |
xmlFile = "/" + xmlFile | |
mgr.getLogger().debug("SpringVerticleFactory: ${xmlFile}") | |
Verticle verticle = null | |
def ctx = clazz.newInstance() | |
ctx.setClassLoader(parentCL) | |
ctx.setConfigLocation(xmlFile) | |
ctx.refresh() | |
verticle = (Verticle) ctx.getBean("verticle") | |
return verticle | |
} | |
@Override | |
void reportException(Throwable t) { | |
mgr.getLogger().error("SpringVerticleFactory failed", t) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment