Spring Boot project in IntelliJ IDEA stops working after reboot - maven

This is probably a newbie question, but I am not able to sort things out.
I've created a Spring Boot JAR-based Maven project using the Spring Initializr interface in IntelliJ IDEA. Its dependencies on Web and JDBC; an embedded instance of Tomcat is used to run the project.
I also have a couple of other Maven dependencies I add without problems from the relevant dialog; I also manually add the Apache Phoenix thin client JAR, that includes a copy of Logback (I am not able to get their Maven repository to work, but I don't think this is relevant to this question).
I am able to run the project flawlessly; after a system reboot (I am on Windows), a cascade of errors follows. First and foremost an exception signaling a conflict between Logback comes:
Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.Log4jLoggerFactory loaded from [...]). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Log4jLoggerFactory.
I would not like to alter the Phoenix client JAR; I am able to follow the instructions to replace the Spring dependency on Logback with another logger (log4j2 for example), but then the embedded Tomcat fails to create the container.
To get back to work, I have to recreate the project from scratch.
Could you please point me in the right direction to pinpoint the actual problem? Thank you.
Post scriptum: I am attaching the content of my pom.xml, apart from some potentially identifying information.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>[RETRACTED]</groupId>
<artifactId>[RETRACTED]</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>[RETRACTED]</name>
<description>[RETRACTED]</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

Firstly, rather than adding the apache phoenix client (or any other dependencies) manually you should add them to your maven pom.xml, so maven resolves the dependency at build time. If your project has dependencies which maven is failing to resolve this is a separate issue which you need to resolve, but adding them manually is bad practice for a number of reasons.
Once you have added the phoenix client as a dependency, you need to explicitly exclude slf4j-log4j12 and log4j as part of the dependency declaration. The XML should look something like this:
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-core</artifactId>
<version>4.13.1-HBase-1.3</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
The reason these need excluded is that they are conflicting with the versions bundled in the spring-boot project
Hopefully this will sort your problem.

Related

How to run Swagger 3 on Spring Boot 3

Using a fresh Spring Initialzr with Java17 and Spring Boot 3.0.0, and an extra addition to the pom.xml for Springfox Swagger 3, I can't for the life of me get Swagger pages to work. Instead, I get the whitelabel error page with 404.
Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
The standard Swagger URLs as defined in this Github Issues page aren't working for the above pom.xml project.
I had given up and went to use Spring Boot 2.7 after posting the question. But, after seeing Dmitriy's answer though, I checked Springdoc one last time and found that Springdoc v2 does support Spring Boot 3.
Essentially, one has to place the following in their pom:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.0</version>
</dependency>
Then one can access the Swagger page using the following URL: http://localhost:8080/swagger-ui.html (Don't forget to add context path if you need it). For some reason, when opening, it redirects to http://localhost:8080/swagger-ui/index.html although going for that initially returned 404...
in addition to adding springdoc-openapi-starter-webmvc-ui (v2.0.2 for me) as indicated in the accepted answer, I also needed to remove org.springdoc:springdoc-openapi-ui:1.6.13 .
It was there because I had tried it before. If present, there's still a non Jakarta reference that Spring tries to resolve (and fails to do so).
I also needed to add this dependency, otherwise I would have a nasty message at startup (version is resolved by Spring Boot BOM) :
implementation group: 'org.hibernate.validator', name: 'hibernate-validator'
Lastest
springfox-boot-starter version 3.0.0
and
springdoc-openapi-ui 1.6.13
seems not to support spring-boot 3.
We need to wait until the new version adopts jakarta.servlet package
Springdoc is working with Spring boot 3.0.1
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.2</version>
</dependency>
Default URL: http://localhost:8080/swagger-ui/index.html
For Gradle you can add this:
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.0'
I agreed with #Ahmed Tawfik because I also faced the same. But today I tried that same approach with the new version of "springdoc-openapi-starter-webmvc-ui" dependency and Spring Boot 3.0.2-SNAPSHOT.
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.2</version>
</dependency>
because the previous one "springdoc-openapi-ui" is changed to the above one.
Also, include below the path to the security config for swagger UI.
"/v3/api-docs/**","/swagger-ui/**"
For my project,
#Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http.cors(AbstractHttpConfigurer::disable)
.csrf(AbstractHttpConfigurer::disable)
.exceptionHandling(exceptionHandlingConfigurer -> exceptionHandlingConfigurer.authenticationEntryPoint(unauthorizedHandler))
.authorizeHttpRequests(authorizationManagerRequestMatcherRegistry -> {
try {
authorizationManagerRequestMatcherRegistry
.requestMatchers(HttpMethod.POST, POST_AUTH_WHITELIST).permitAll()
.requestMatchers(HttpMethod.GET, GET_AUTH_WHITELIST).permitAll()
.requestMatchers("/v3/api-docs/**", "/swagger-ui/**").permitAll()
.anyRequest()
.authenticated()
.and()
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
} catch (Exception e) {
throw new ResourceNotFoundException(e.getMessage());
}
}
)
.formLogin(AbstractHttpConfigurer::disable)
.httpBasic(AbstractHttpConfigurer::disable).addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
.authenticationProvider(daoAuthenticationProvider()).build();
}
The swagger UI link will be:
http://server:port/context-path/swagger-ui.html
Please adjust the server, port, and context-path regarding your personal changes.
All the above steps are working fine with my project. I don't need extra configuration.
Also, you can add the custom path (Optional):
springdoc.swagger-ui.path=/swagger-ui.html
Here is the Official Documentation of OpenApi 3 and Spring Boot : https://springdoc.org/v2/#features
In the above documentation, you can explore additional configurations and other things also.
Happy Learning! ✌️
Use Open API instead swagger for Spring v3.0. Follow this document Open API Docs
Following dependencies working fine to me.
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sample.app</groupId>
<artifactId>hello-world</artifactId>
<version>1.0.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.1</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
</project>

Spring boot 2.1.7 having tomcat-embed-core conflit

I am migrating existing Spring project into Spring boot.unable to run spring boot application its showing following error.
The error log says there is a conflict on tomcat-embed-core.
In eclipse Dependency hierarchy of porm.xml is given below
i exclude the maven architect ,and try to run the application its showing following error
porm.xml
<modelVersion>4.0.0</modelVersion>
<artifactId>MyService</artifactId>
<packaging>jar</packaging>
<properties>
<java.version>1.8</java.version>
<!-- 2.1.3.RELEASE -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<springframework.boot.version>2.1.7.RELEASE</springframework.boot.version>
</properties>
<name>MyService</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.sybase.jdbc3.jdbc</groupId>
<artifactId>jconn3</artifactId>
<version>${jconn3.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-juli</artifactId>
<version>${tomcat.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
<version>${tomcat.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
what was wrong in this porm.xml
Where is
${tomcat.version}
defined?
That version probably does not match the tomcat version that auto magically is included with spring boot items.
And thus the conflict.
Go here:
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web/2.1.7.RELEASE
And start following the COMPILE dependencies, and you'll find the versions that are auto included with 2.1.7.RELEASE. and you have to alter the other includes that are overwriting the springboot auto include tomcat versions.
Again, follow the COMPILED dependency trail.
So below is what you should find by crawling the COMPILED dependency trail (from immediately above in my answer)
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-tomcat/2.1.7.RELEASE
And you'll find you need to set
tomcat.version to
9.0.22
By defining tomcat.version as 8.x, you are breaking it.
Another way to put it
You have to go ~way~ back to springboot 1.5.2.RELEASE or 1.5.3.RELEASE
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-tomcat/1.5.2.RELEASE
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-tomcat/1.5.3.RELEASE
(Again, in the two above links, looked at the COMPILE dependencies)
To find a version of tomcat (that is auto included with springboot) that gets close to tomcat 8.5.x (where 8.5.x is the one you are attempting to use)
That's pretty old.
The principal you are missing is that springboot auto includes dependencies. And anything else you import has to play nice with everything springboot auto includes.
And your current value for tomcat.version is NOT playing nice with everything springboot 2.1.7.RELEASE is auto including.
And now that you've been through all of that. You'll find you'll make your life easier if you engage the springboot world more completely.
Alot of times, springboot will have a (sub)package that will bring in the thing you really desire.
spring-boot-starter-jdbc
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc/2.1.7.RELEASE
You would probably be better off bringing that package in, vs hand-picking ones. Aka, get rid of your "tomcat-jdbc" include and see if the spring-boot-starter-jdbc can give you what you want.
The curse/blessing of spring-boot is that it is its own universe. But if you engage, you probably want to play by its rules more often than not.
PS
It is pom.xml, not porm.xml
Try adding spring-boot-starter-tomcat as a dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
Remove tomcat-juli and tomcat-jdbc dependencies. If you need JDBC support, add the corresponding starter:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
If you use JSP views, you will probably need the following dependencies as well:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
Also, pay attention to your dependencies versions. Spring Boot's parent POM defines version management for many common artifacts so you don't need to set the <version></version> for these libraries. See https://docs.spring.io/spring-boot/docs/2.1.7.RELEASE/reference/htmlsingle/#appendix-dependency-versions

Failed to load class "org.slf4j.impl.StaticLoggerBinder", Spring Boot

I'm using Spring Boot 1.5.8. SLF4J doesn't seem to be working for me. Here is what I get in the console at the beginning of a project run. The below error shows appears :
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
START : EDIT 1 :
My console doesn't log the below:
LOGGER.error("ERROR");
LOGGER.error("WARN");
LOGGER.error("INFO");
LOGGER.error("DEBUG");
LOGGER.error("TRACE");
All I get is those three lines of error(warning) as the first lines in my console.
END : EDIT 1 :
I looked up the internet and found multiple issues titled as this,tried the suggestions but that didn't resolve my issue. I came across this stackoverflow question where Konstantinos hints at the possibility of presence of multiple slf4j dependencies. Other solutions on the internet also suggested that; even the official site confirmed that to be the reason for such error.
Also checked my effective pom just to eliminate this possibility and found that my effective pom does contain all the 4 dependencies that he mentioned. The general suggestion is that the pom should contain only one of these four dependencies. But , since this was all handled by Spring boot, I'm a bit confused as to how do I go about resolving this, because I never exclusively included any slf4j dependency in my pom. So I'm unable to follow the suggestion.
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.codingethics.flightreservation</groupId>
<artifactId>flightreservation</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>flightreservation</name>
<description>Flight Reservation Application</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-jasper -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.itextpdf/itextpdf -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.13</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-mail -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.properties :
spring.datasource.url=jdbc:mysql://localhost:3306/reservation
spring.datasource.username=root
spring.datasource.password=password
spring.jpa.show-sql=true
spring.mvc.view.prefix=/WEB-INF/jsps/
spring.mvc.view.suffix=.jsp
server.context-path=/flightreservation
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=<myusername>
spring.mail.password=<mypwd>
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
Why does this dependency-conflict(if at all that's the case here) happen in a Spring Boot project. Isn't Spring Boot meant to be looking after these beforehand.
Any sort of help/ guidance is highly appreciated.
START : EDIT for #Antot
I get NoClassDefFoundError.(followed steps as advised by you) :
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:179)
at com.codingethics.flightreservation.FlightreservationApplication.main(FlightreservationApplication.java:10)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more
END : EDIT for #Antot
You might first want to check if something that isn't managed by Spring Boot is pulling in additional dependencies. You can do this with mvn dependency:tree to see what is pulling in what.
If that doesn't give a hint in the right direction it might be that one of your downloaded dependencies got borked. You might want to purge the local repository. You can do this with mvn dependency:purge-local-repository to remove all your dependencies from your local maven repository.
Then when doing mvn package (or another task that will compile and build the jar) will (re)download the jars and hopefully in a correct way without corruption.

Neither Spring Boot Actuator + Hal-Browser nor DevTools working

Updated: Attached pom.xml and application.property and some more error / warning msgs.
Hi I am very new to Spring Boot and just taking some classes on Udemy for it.
While following through a class, I create a starter project via spring.io and added actuator and Hal browser dependencies including Dev tools.
Just ran my app and tried to go to localhost:8080/application & /browser as well but I get 404.
What am I doing wrong?
I wrote a simple bean which returns a hard coded value and then print that, I changed the value to test Dev tools and it didn’t restart the resource , I had to kill and restart the app to reflect the new changes ..
How can I check what the issue ?
I can provide console grab if needed.
Please help.
Update: I don't know the significance of the following so putting it in here.
in the XML editor hal is red underlined with the following msg on hover:
The managed version is 3.0.5.RELEASE The artifact is managed in org.springframework.data:spring-data-releasetrain:Kay-SR5
in the XML editor devtools is red underlined with the following msg on hover:
The managed version is 2.0.0.RELEASE The artifact is managed in org.springframework.boot:spring-boot-dependencies:2.0.0.RELEASE
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myoxigen.training.springboot</groupId>
<artifactId>library</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>library</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-browser</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.properties file:
logging.level.org.springframework = DEBUG
management.security.enabled=false
Note: This answer is based on Spring Boot 2 (paths and properties have changed from version 1).
Your pom.xml looks fine to me. To get the "HAL Browser" to work with actuator you should have starters: web, actuator, and Rest Repositories HAL Browser. I recommend Spring Initializr as a nice way to construct an initial valid project structure.
The default path for the actuator is /actuator. Health, for example, is at /actuator/health.
To view the actuator endpoints in the HAL Browser, go to /browser/index.html#/actuator.
You can change the actuator path in application.properties by setting the following.
management.endpoints.web.base-path=/actuator
To run your server, use the following console command:
./mvnw clean spring-boot:run
If you have DevTools in your project, then changes to files in your classpath will restart the server. See my further comments on how to take advantage of DevTools here.
Here's the relevant documentation on a single page for easy searching:
https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle
Add this Dependency:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-browser</artifactId>
<version>3.3.5.RELEASE</version>
</dependency>`enter code here`
And then go to link:
http://localhost:8080/browser/index.html#
Spring Boot 2.2 apps should use spring-data-rest-hal-explorer rather than spring-data-rest-hal-browser
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-explorer</artifactId>
</dependency>
For enabling actuator, add this into the property file (application.properties)
management.endpoints.web.exposure.include=*
Restart the Spring boot application and access the actuator endpoints using:
http://localhost:8080/actuator/
the health of the application can also be monitored using:
http://localhost:8080/actuator/health
dependency required:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Ain't you were studying a course by "in28minutes"? =) Anyway when I studied on a Spring Boot for Beginners in 10 Steps course, I faced the same issue with accessing http://localhost:8080/application.
For http://localhost:8080/browser I got a plain json:
{"cause":null,"message":"Fragment must not be empty"}
In pom.xml I had the same dependencies as you outlined in question.
Some googling brought me to this article. In section named "II. Hal Browser" you can see a screenshot, where in browser a link is http://localhost:8080/browser/index.html#. If use this link, then Hal Browser should magically appear.
So /index.html# was the only puzzle piece you missed.
Note: above approach worked with Spring Boot version 2.1.7
EDIT: despite the fact that Hal Browser itself works with above approach, it still doesn't show actuator endpoints. And DevTools also ain't working for me.

SpringBoot app shows Whitelabel Error Page while serving JSP from JAR

I am exploring how JSPs can be served from JAR file. I'm using SpringBoot 1.5.10.RELEASE
I referred this & this examples and was able to create spring boot app which
includes JSPs at location src/main/resources/META-INF/resources/WEB-INF/jsp/
view resolver has prefix as /WEB-INF/jsp/ and suffix as .jsp
Strange thing is when I ran project as springboot app or Java App, I was able to hit the controller and got desired JSP file as response. After that I thought of packaging the app and then running it from JAR.
$ mvn package
$ java -jar target/springboot-web-jar-demo-0.0.1-SNAPSHOT.jar
Spring boot app comes up, when I hit the same URL pattern, control comes in the mapped method but after that...
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Feb 28 21:01:09 IST 2018
There was an unexpected error (type=Not Found, status=404).
/WEB-INF/jsp/index.jsp
My problem/question...
Is there any major difference between the springboot app runs in IDE and when it runs as JARs, which can even cause 404?
Does spring boot 1.5.10.RELEASE support serving JSPs from JAR? (if yes then what I'm missing here, if no then where it is mentioned) - stackoverflow-link
I have tried searching proper solution or answer to my problem but didn't get any. Hence posting the question here please help.
Note:
Please don't provide solution for WAR packaging
I know JSP are not best choice nowadays, I'm just learning
I'm aware that I can look for alternatives like thymeleaf, freemarker and velocity
I don't want to downgrade the SpringBoot version
I've also tried specifying <scope> of jasper & JSTL to provided and compile but no luck
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.atuldwivedi.learn.springboot</groupId>
<artifactId>springboot-web-jar-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>springboot-web-jar-demo</name>
<description>Learn how to serve JSP from JAR</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<relativePath />
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
For you spring boot recognize their jsps, you debt create a webapp directory in src.main like this:
src/main/webapp/WEB-INF/jsp
and not like:
src/main/resources/META-INF/resources/WEB-INF/jsp
for dispatcherServelet recognize their jsps, you create a webapp directory in src.main like this:
src/main/webapp/WEB-INF/jsp
and also autoconfigure your application in application.properties
spring.mvc.view.prefix:/WEB-INF/jsp
spring.mvc.view.suffix:.jsp`
JSPs are not supported when using an executable jar.

Resources