Spring Loaded: Integration with Spring MVC maven project
Asked Answered
M

5

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.

Me answered 7/5, 2014 at 6:19 Comment(6)
@Ischin, there is no error message. TOMCAT starts up clean.Me
Try change the backslash (\) to forward slash (/)Crazy
Vaibhav, were you able to get this working?Upheave
@Upheave Unfortunately not. I spent a lot of time on this. Finally I got JRebel Social.Me
It seems that spring-loaded don't provide any documentation on how to defined the location of the new compiled classes, so they can be reloaded.Anemology
Related: https://mcmap.net/q/949182/-intellij-tomcat-spring-loaded/435605Anemology
S
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.

Stuyvesant answered 9/7, 2014 at 12:52 Comment(0)
F
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.

Familiarity answered 7/5, 2014 at 14:43 Comment(6)
A bit more detailed information with images on publishing and auto reload is at https://mcmap.net/q/1481379/-what-happens-when-i-run-an-application-on-tomcat-in-eclipse (a little self-promotion :)).Perdue
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.Me
I've tried this in STS and Tomcat 7 with a very simple Spring web app with changing code in a @Controller annotated class.Familiarity
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)Familiarity
@Vaibhav Do you have Build Automatically checked (menu Project)?Perdue
@Pavel Yes, I do have 'Build Automatically' checked.Me
D
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

Dowie answered 7/3, 2015 at 7:38 Comment(0)
C
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!!!

Coreencorel answered 30/7, 2015 at 18:57 Comment(1)
Does this still work? Because I can not get this to work at all. See -> #35014828Wellbred
R
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.

Rearmost answered 10/1, 2017 at 16:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.