IntelliJ + Tomcat + Spring-Loaded

一个人想着一个人 提交于 2019-11-30 07:10:54

问题


I would like to try out Spring Source's "Spring Loaded" class reloading agent, with Tomcat run via IntelliJ.

https://github.com/SpringSource/spring-loaded

I've added the JVM arguments to my Tomcat run configuration, and my webapp starts up without errors and seems to behave normally.

I'm not really sure how to trigger the class reloading though. Do I just need to compile the classes that I modify? I've tried that and that didn't seem to work. Do I need to update Tomcat and deploy classes and resources? That doesn't seem to work either...?

Any specific configuration details would be greatly appreciated.

EDIT: More info, I think my problem may have to do with using two modules, one a core code library, and one the webapp. I use Maven for both, one configured as a jar project and the other as a war project. IntelliJ sets up the Artifact for the exploded war to use the jar module's jar file. I've tried switching the Artifact config to incorporate the jar module's compiled output into WEB-INF/classes instead. Now I see the .class files in target/webapp/WEB-INF/class/etc. But I'm not sure how to get IntelliJ to update a specific class file when I edit it.


回答1:


If you added the following jvm parameters (as described at the springloaded page) to your tomcat

-javaagent:<pathTo>/springloaded-{VERSION}.jar -noverify SomeJavaClass

you should be fine. It may help to disable auto reloading in tomcat for the webapp you are testing. For exmaple in your server.xml:

<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
    <Context docBase="projekt" path="/projekt" reloadable="false" ...

This ensures that only the springloaded classloader loads changed classes.




回答2:


spring loaded cannot hotswap jars.

Put web fragment output into webapp/WEB-INF/classes

Also spring loaded support only spring 4.1 https://github.com/spring-projects/spring-loaded/issues/139



来源:https://stackoverflow.com/questions/15118681/intellij-tomcat-spring-loaded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!