intelij spring boot hot swap causes context reload - spring-boot

I am using Intellij 2017.2 with Spring Boot 1.5.4
When I recompile my current class with ctr+shift+F9, instead of the IDE doing a bytecode hotswap, the spring container gets reloaded.
On top of that, after the reload my RestConroller no longer works
I have tried adding / removing from my pom
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
please advise

I am not sure if this is a spring boot bug as of the new version, but I ended up disabling manually the hot reload via properties:
This is done by setting the following in your application.properties:
spring.devtools.restart.enabled=false
The official doc:
https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html#using-boot-devtools-restart-disable

Related

Unable to serve JSP in Spring Boot applications

I have tried several tutorials to serve JSP pages using Spring Boot. They all return a 404 page not found error.
To overcome the known limitations, I'm using a WAR packaging, with the following dependencies:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
I have defined the path where JSP pages are in application.properties:
spring.mvc.view.prefix= /WEB-INF/jsp/
spring.mvc.view.suffix= .jsp
When requesting a JSP page, the following WARN is displayed:
WARN 10251 --- [io-8080-exec-11] o.s.w.s.r.ResourceHttpRequestHandler : Path with "WEB-INF" or "META-INF": [WEB-INF/jsp/hello.jsp]
Have JSP been deprecated in Spring Boot 2? Do you have any Spring Boot 2 working example with JSP ?
can you please try adding scope in your dependency just like this
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
I'm using Intellij IDEA. I found out that we cannot just run the SpringBootApplication main class directly. We need to let the maven do the work.
Short solution: maven run you application by the command below from your module root directory
mvn clean package spring-boot:run
You can also add a run configuration using Maven so that you don't have to type the command every time.
Some said JSPs folder should be put under src/main/resources/META-INF/resources/WEB-INF/jsp. This indeed solves the spring boot application run problem though, it will fail when you run the application using tomcat. So we still need to keep the structure if we are going to deploy the application to Tomcat.
Unfortunately, I couldn't find any Spring Boot 2 example able to serve JSP pages as they all return a 404 error. As a workaround I have configured the application to be deployed on WildFly, as described in this tutorial and run my application with JSP on WildFly.
If you want example here it is.
This also help you.

How to override the spring boot version used by jhipster

my JHipster generated application uses
<jhipster-dependencies.version>2.0.28</jhipster-dependencies.version>
which includes Spring Boot v.2.0.6
But I want to use Spring Boot 2.1.1
What do I need to change in my pom.xml to achieve that.
I tried to set <spring-boot.version>2.1.1.RELEASE</spring-boot.version>
But when I build & run, still v2.0.6 is used.
Thanks for asking this question. The comment to your question by Gael pointed me in the right direction. I've just completed an upgrade of my legacy project. Here is how I did it:
Go to this link: https://www.jhipster.tech/upgrading-an-application/
Follow the instructions for automatic upgrade ( Make sure before you upgrade that you create a new branch, there are sure to be merge conflicts).
Resolve the merge conflicts and run your tests.
Commit the changes to avoid having to repeat the work.
Above all read the instructions and understand them before beginning because otherwise you will become frustrated.
You can get the list of JHipster release versions here: https://www.jhipster.tech/releases/
I faced the same problem, my jhipster version is 3.9.1 and spring boot's version is 2.2.7.RELEASE.
So to upgrade spring-boot.version to latest 2.7.5:
Add dependency management from Spring Boot before Jhipster as follow:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.github.jhipster</groupId>
<artifactId>jhipster-dependencies</artifactId>
<version>${jhipster-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
It worked for me

Breakpoints and maven options are ignored when using spring devtools

I'm trying to use spring devtools for my project. When I add devtools dependency breakpoints stopped working and maven options are ignored. I'm using Netbeans.
I added dependency into pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
And this is the netbeans action for debug:
Executed goal: spring-boot:run
Profile: dev
Properties:
jpda.listen=maven
Env.MAVEN_OPTS=-Dflyway.enabled=false
Breakpoints and maven options (MAVEN_OPTS) are working fine without devtools dependency. Adding the devtools dependency causes "-Dflyway.enabled=false" option and breakpoints being ignored. The maven command with all arguments generated by Netbeans is the same, I can see it in the log output. Is there anything else I have to set for devtools?
I found the answer, the properties in action must be written this way (spring boot 2.0.0):
spring-boot.run.jvmArguments=-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -Dspring.flyway.enabled=false
jpda.listen=true
For spring boot version < 2.0.0 it is:
run.jvmArguments=-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -Dflyway.enabled=false
jpda.listen=true

Create a Spring Boot 1.5.8 Quartz scheduler app

I want to create a Spring Boot Quartz scheduler app. using Spring Boot 1.5.8 with Spring Tool Suite Version: 3.9.0.RELEASE using the option Spring Starter Project, but the Quartz scheduler option is disabled:
I also tried to added manually adding to the pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
and then I got the error:
Project build error: 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-quartz:jar is
missing.
You have to create your spring-boot starter app with version >= 2.0.0.M2. At start.spring.io you can see for which version some dependencies are available.
After using the correct version, everything should work.

spring boot fails to run - IllegalAccessError on startup

I have a strange issue and that I have not been able to resolve. I am trying to use the sample JPA sprint boot (v0.5.0-M6) project as a starting point for an application I am writing. I grabbed the JPA sample and got that to run locally. I then proceeded to add my code into that project. I imported into eclipse and run as spring-boot. Then I get this error:
Exception in thread "main" java.lang.IllegalAccessError: tried to access class org.springframework.core.io.DefaultResourceLoader$ClassPathContextResource from class org.springframework.boot.context.embedded.EmbeddedWebApplicationContext
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getResourceByPath(EmbeddedWebApplicationContext.java:386)
at org.springframework.core.io.DefaultResourceLoader.getResource(DefaultResourceLoader.java:100)
at org.springframework.context.support.GenericApplicationContext.getResource(GenericApplicationContext.java:211)
at org.springframework.boot.context.initializer.ConfigFileApplicationContextInitializer.load(ConfigFileApplicationContextInitializer.java:192)
at org.springframework.boot.context.initializer.ConfigFileApplicationContextInitializer.load(ConfigFileApplicationContextInitializer.java:134)
at org.springframework.boot.context.initializer.ConfigFileApplicationContextInitializer.initialize(ConfigFileApplicationContextInitializer.java:121)
at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:403)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:287)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:749)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:738)
From what I can tell, this is the wrong application context, since I am not using XML configuration but annotations to drive the configuration. Spring boot is automatically selecting this one and I need to tell it not to use the above. At least that is what I think I need to do.
I did search here and in the spring.io forums but no one seems to have the same issue.
Question: What drives the selection of an application context with the auto configuration?
What should I be looking at to resolve the above issue? What else do I need to provide to here help debug the auto configuration issue?
TIA,
Scott
I got the same problem.
if you use maven check your pom.xml
remove conflict version in Spring Lib.
<properties>
<hibernate.version>4.2.0.Final</hibernate.version>
<mysql.connector.version>5.1.21</mysql.connector.version>
<spring.version>3.2.2.RELEASE</spring.version>
</properties>
i remove this line
<spring.version>3.2.2.RELEASE</spring.version>
and in maven dependency just
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
Hope this help.
I was facing the same problem, and solved fixing the referencing to the boot-starter-parent pom.
At the pom.xml file I used:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>0.5.0.M6</version>
</parent>
I have some urgent issues to fix now, so I didn't inspected this parent pom to see what's so important here, but I hope this can help you - don't forget to verify the version you're using!

Resources