Skip to content

Instantly share code, notes, and snippets.

@rvowles
Created February 8, 2013 04:57
Show Gist options
  • Save rvowles/4736689 to your computer and use it in GitHub Desktop.
Save rvowles/4736689 to your computer and use it in GitHub Desktop.
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