7

I just stumbled upon the Spring Loaded project on the Spring website today. I'm trying to integrate this into a Spring MVC (using Maven and TOMCAT) I've been working on.

As per the instructions on the project page, I've downloaded the JAR file and added the following in the TOMCAT VM arguments (Inside Eclipse):

-javaagent:C:\Users\xxx\Downloads\springloaded-1.2.0.RELEASE.jar -noverify

I've also disabled 'Automatic Publishing' in TOMCAT.

Now, Once I start TOMCAT and make any changes to the controllers (or any other classes), I do not see any hot deployment happening. Is there anything I'm going wrong or is there any other configuration required?

Would appreciate any inputs.

lschin
  • 6,745
  • 2
  • 38
  • 52
va1b4av
  • 431
  • 9
  • 26

5 Answers5

5

I was trying SpringLoaded for a quick demonstration using Petclinic on top of Aptache Tomcat 7 during this week facing same issue as discussed here. Finally I found that I need to add the project to the Tomcat classpath. So in my case, I have opened the Tomcat "launch configuration" in Eclipse, and in the classpath tab, I have added my project in the "user entries" group. This causes springloaded works fine.

viarellano
  • 51
  • 1
  • 2
4

You DO need "Automatic Publishing" in Tomcat, because the changed .class files are not copied to the temporary folder where Tomcat has the application deployed to.

For example, in my local instance, the temporary Tomcat deployment folder is [WORKSPACE_FOLDER]\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps. In this folder I have my Eclipse web app resources (classes and other files) copied over and this is where Tomcat is picking them up for deployment. While my Eclipse web app has its .class files compiled in [WORKSPACE_FOLDER]\[MY_WEB_APP_FOLDER]\target when I change one class source code, the class is recompiled and its .class file placed in target folder. With "Automatic Publishing" enabled the .class files from target folder above ARE copied over to wtpwebapps folder, whereas with that option disabled there is no copying over.

"Automatic Publishing" doesn't also mean that the application is redeployed on Tomcat, its updated .class files and other files are updated in the wtpwebapps folder, as well.

What you do need to disable in Tomcat, though, is the "Auto Reload" option for your web module. Double-click on the Tomcat Server created in Eclipse, go to "Modules" tab, click on your web app web module, then click on "Edit..." and uncheck "Auto reloading enabled". Save and restart your Tomcat.

Andrei Stefan
  • 51,654
  • 6
  • 98
  • 89
  • A bit more detailed information with images on publishing and auto reload is at http://stackoverflow.com/a/17510281/865403 (a little self-promotion :)). – Pavel Horal May 07 '14 at 15:27
  • Thanks for the detailed responses @Andrei and Pavel. I've disabled 'Auto Reload' and enabled 'Automatic Publishing'. I've even tried using this on STS and TOMCAT. Nothing seems to work here. – va1b4av May 07 '14 at 15:55
  • I've tried this in STS and Tomcat 7 with a very simple Spring web app with changing code in a @Controller annotated class. – Andrei Stefan May 07 '14 at 15:57
  • As a sign of something happening when I change my @Controller code, I am seeing this in the logs: `INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.foo.bar.HomeController.home(java.util.Locale,org.springframework.ui.Model)` – Andrei Stefan May 07 '14 at 16:49
  • @Vaibhav Do you have *Build Automatically* checked (menu *Project*)? – Pavel Horal May 07 '14 at 19:29
  • @Pavel Yes, I do have 'Build Automatically' checked. – va1b4av May 10 '14 at 02:47
1

I have a spring mvc project. I use eclipse to write code but do not use it to run or test the application. Hot deployment with my setup works perfectly. I will give the steps to set this up.

Step #1

Download Spring Loaded Jar from here

Step #2

Edit your maven batch / shell file and add this line

export MAVEN_OPTS="-javaagent:/path/to/your/jar/springloaded-1.2.1.RELEASE.jar -noverify"

Step #3

Turn on Build Automatically in eclipse [menu: Project -> Build Automatically]

Step #4

Configure you pom to use tomcat plugin

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.0</version>
    <executions>
      <execution>
      <id>run-embedded</id>
      <goals>
        <goal>run</goal>
      </goals>
   <phase>pre-integration-test</phase>
   <configuration>
    <useSeparateTomcatClassLoader>true</useSeparateTomcatClassLoader>
    <contextFile>${basedir}/tomcat/context.xml</contextFile>
   </configuration>
  </execution>
 </executions>
</plugin>

Step #5

Run you app using mvn tomcat:run

Community
  • 1
  • 1
Arindam
  • 537
  • 1
  • 5
  • 8
0

If you want to integrate Spring-Loader you need add

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>springloaded</artifactId>
            <version>1.2.3.RELEASE</version>
        </dependency>
    </dependencies>
</plugin>

into pom.xml

That's it. Cheers!!!

abosancic
  • 1,776
  • 1
  • 15
  • 21
  • Does this still work? Because I can not get this to work at all. See -> http://stackoverflow.com/questions/35014328/spring-loaded-1-2-5-spring-boot-1-3-2-cant-seem-to-get-it-to-work – Ronner Jan 26 '16 at 13:13
0

I have a spring mvc project, tomcat7-maven. I use eclipse to write code. I config my project as below:

Step #1 : pom.xml

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
    <!-- Config: contextPath and Port (Default: / : 8080) -->
    <configuration>
        <path>/</path>
        <port>8080</port>
    </configuration>
</plugin>

Step #2

Download Spring Loaded Jar from here: springloaded-1.2.5.RELEASE.jar

Step #3

Right click on your project→ Run As → Run Configurations… → Maven Build → New →

Tab Main:

  • Name: Your Configuration's Name
  • Base directory: ${workspace_loc:/YourProjectName}
  • Goals: tomcat7:run -X

Tab Arguments: At VM Arguments: -javaagent:path/to/library/springloaded-1.2.5.RELEASE.jar -noverify

→ Run

Now you can modify the source code and see the changes immediately. Simply by reloading the page in the web browser, without rebuilding your project (Eclipse build automatically) and have to restart the web server.

Giang Phan
  • 534
  • 7
  • 15