Jrebel clear Mybatis interceptors when reload Mapper XML files -
i'm using jrebel 6.3.0 hot reload mybatis's mapper xml spring boot web application. , used java configuration config mybatis.
@configuration @conditionalonclass({ pageinterceptor.class }) @enableconfigurationproperties(mybatispageproperties.class) @autoconfigurebefore(mybatisautoconfiguration.class) public class mybatispageautoconfiguration implements applicationcontextaware { private static final logger log = loggerfactory.getlogger(mybatispageautoconfiguration.class); @autowired private mybatispageproperties properties; @override public void setapplicationcontext(applicationcontext applicationcontext) throws beansexception { beanutil.setapplicationcontext(applicationcontext); } /** * * * @return */ @bean public pageinterceptor pageinterceptor() { log.info("========pageinterceptor========"); pageinterceptor pageinterceptor = new pageinterceptor(); properties p = new properties(); p.setproperty("dialect", properties.getdialect()); p.setproperty("sqlidregex", properties.getsqlidregex()); pageinterceptor.setproperties(p); return pageinterceptor; }
i found jrebel clear interceptors when reload mapper xml file.
org.zeroturnaround.jrebel.mybatis.sqlmapreloader
private void reconfigure() { log.infoecho("reloading sql maps"); this.conf.reinit(); // clear loadedresources , interceptors reloadedresources.set(collections.synchronizedset(new hashset())); enterreloading(); try { if (this.confbuilder != null) this.confbuilder.reinit(); reconfigureadditionalmappings(); exitreloading(); reloadedresources.remove(); } { exitreloading(); reloadedresources.remove(); } } ......... private void reconfigureadditionalmappings() { (resourcedesc rd : (resourcedesc[])this.additionalmappings.toarray(new resourcedesc[0])) { reconfiguremapping(rd); } } private void reconfiguremapping(resourcedesc rd) { org.apache.ibatis.session.configuration c = (org.apache.ibatis.session.configuration)this.conf; try { // reload loadedresources mapper xml files. xmlmapperbuilder xmlmapperbuilder = new xmlmapperbuilder(resourceutil.asinputstream(rd.url), c, rd.path, c.getsqlfragments()); xmlmapperbuilder.parse(); } catch (exception e) { if ((e.getcause() instanceof java.io.filenotfoundexception)) removemappingfordeletedresource(rd); else { throw new runtimeexception("failed parse mapping resource: '" + rd.url + "'", e); } } { errorcontext.instance().reset(); } }
org.zeroturnaround.jrebel.mybatis.cbp.configurationcbp
public class configurationcbp extends javassistclassbytecodeprocessor { public void process(classpool cp, classloader cl, ctclass ctclass) throws exception { ctclass.addinterface(cp.get(jrconfiguration.class.getname())); ctclass.addfield(new ctfield(cp.get(sqlmapreloader.class.getname()), "reloader", ctclass)); ctconstructor[] constructors = ctclass.getconstructors(); (int = 0; < constructors.length; i++) { ctconstructor constructor = constructors[i]; if (constructor.callssuper()) { constructor.insertafter("reloader = new " + sqlmapreloader.class.getname() + "($0);"); } } ctclass.addmethod(ctnewmethod.make("public " + sqlmapreloader.class .getname() + " getreloader() {" + " return reloader;" + "}", ctclass)); ctclass.addmethod(ctnewmethod.make("public void reinit() { loadedresources.clear(); ((" + jrinterceptorchain.class .getname() + ") interceptorchain).jrclear();" + "}", ctclass)); ctclass.getdeclaredmethod("isresourceloaded").insertafter("if (reloader.doreload($1)) { loadedresources.remove($1); $_ = false;}"); } }
is there anyway let jrebel keep interceptors?
my project web app, don't need change in prod-env, use jrebel in dev-env, modify source file fetch form source jar, , place in src/test/java, , build classes dir, , replace class in original jar. don't place in src/main/java folder.
org.apache.ibatis.builder.xml.xmlmapperbuilder
... public class xmlmapperbuilder extends basebuilder { private static list<interceptor> interceptors = new arraylist<interceptor>(); // added yuanjinyong ... public void parse() { ... parsependingstatements(); // added yuanjinyong if (interceptors.size() == 0) { interceptors.addall(configuration.getinterceptors()); } if (configuration.getinterceptors().size() == 0) { (interceptor interceptor : interceptors) { configuration.addinterceptor(interceptor); } } } ... }
Comments
Post a Comment