Issues I faced during use of SpringBoot
It has been quite a time since I studied SpringBoot, so thought to revisit that & here I will share the issues I faced in creating SpringBoot simple application on my system
===============================================================================================
While creating the Spring DB project with 2.1.5.RELEASE & jdk8, I see some unknown error being reported by pom.xml
I could have ignored that even, if I would have been able to start my application.
So after searching on google I followed below steps one by one -
a) Changed the above version to 2.1.4.RELEASE & then did forced Maven update in Eclipse.
And yes, the error in pom.xml is gone. I just tried to 'Run as' the project as 'Spring Boot App' But now I am getting below
logs & embedded server stops immediately -
2019-08-30 11:38:34.513 INFO 8596 --- [ main] com.example.demo.Application : Starting Application on DESKTOP-CK7JQ5R with PID 8596 (E:\Workspaces\STSWorkspaces\SpringApps\com.dbapplications.repositories\target\classes started by nitin in E:\Workspaces\STSWorkspaces\SpringApps\com.dbapplications.repositories)
2019-08-30 11:38:34.516 INFO 8596 --- [ main] com.example.demo.Application : No active profile set, falling back to default profiles: default
2019-08-30 11:38:34.830 INFO 8596 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-08-30 11:38:34.844 INFO 8596 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 8ms. Found 0 repository interfaces.
2019-08-30 11:38:35.124 INFO 8596 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-08-30 11:38:35.206 INFO 8596 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2019-08-30 11:38:35.243 INFO 8596 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-08-30 11:38:35.285 INFO 8596 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.3.9.Final}
2019-08-30 11:38:35.286 INFO 8596 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2019-08-30 11:38:35.379 INFO 8596 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2019-08-30 11:38:35.467 INFO 8596 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2019-08-30 11:38:35.595 INFO 8596 --- [ main] o.h.t.schema.internal.SchemaCreatorImpl : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@79d743e6'
2019-08-30 11:38:35.597 INFO 8596 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-08-30 11:38:35.712 INFO 8596 --- [ main] com.example.demo.Application : Started Application in 1.44 seconds (JVM running for 2.333)
2019-08-30 11:38:35.716 INFO 8596 --- [ Thread-3] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2019-08-30 11:38:35.716 INFO 8596 --- [ Thread-3] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed evictData of schema as part of SessionFactory shut-down'
2019-08-30 11:38:35.719 INFO 8596 --- [ Thread-3] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2019-08-30 11:38:35.720 INFO 8596 --- [ Thread-3] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
b) Other Google suggestion was to execute the below command for this project -
mvn clean eclipse:clean eclipse:eclipse
But still the results were same server getting stopped.
c) Someone on Stackoverflow suggested to delete the tomcat folder in .m2, as it might be corrupted. And do update of the
project so that it can take the fresh copy. I did but the results were same.
d) Now I changed the above SpringBoot version to 2.0.0.RELEASE & did the force Maven update of the project.
And now I started the project & it worked. For other project I tried 2.2.7.RELEASE & it also worked.
===============================================================================================
If you see that some dependency is not found or jar not found or some jar is corrupted or some issue with the jar, even if you have added its right dependency in your pom.xml
Then go to your .m2 folder & delete those jar/s & do Maven update(may be forcefully). Once it fetched the jars again then you can see your build getting successful.
===============================================================================================
You configured Swagger in your REST API project in Spring Boot & it is not working even if you did as given on the website & still your Swagger API is not available. Then check if in your project you have used @EnableWebMvc for any file in your project. As this annotation doesn't allow Swagger to be configured by itself & you have to either remove this annotation or configure Swagger manually using below code -
@EnableSwagger2
public class SwaggerEnabler implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry
.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
:
:
:
}
Add above method in the class where you configured your Swagger in your project.
Thanks to : https://stackoverflow.com/questions/43545540/swagger-ui-no-mapping-found-for-http-request for the above
answer
===============================================================================================
You have used Spring Security but don't want Swagger to be part of this security then use below code -
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/v2/api-docs",
"/configuration/ui",
"/swagger-resources/**",
"/configuration/security",
"/swagger-ui.html",
"/webjars/**");
}
Add bove method in the class extending WebSecurityConfigurerAdapter
Thanks to : https://stackoverflow.com/questions/37671125/how-to-configure-spring-security-to-allow-swagger-url-to-be-accessed-without-aut for the above answer
===============================================================================================
While creating the Spring DB project with 2.1.5.RELEASE & jdk8, I see some unknown error being reported by pom.xml
I could have ignored that even, if I would have been able to start my application.
So after searching on google I followed below steps one by one -
a) Changed the above version to 2.1.4.RELEASE & then did forced Maven update in Eclipse.
And yes, the error in pom.xml is gone. I just tried to 'Run as' the project as 'Spring Boot App' But now I am getting below
logs & embedded server stops immediately -
2019-08-30 11:38:34.513 INFO 8596 --- [ main] com.example.demo.Application : Starting Application on DESKTOP-CK7JQ5R with PID 8596 (E:\Workspaces\STSWorkspaces\SpringApps\com.dbapplications.repositories\target\classes started by nitin in E:\Workspaces\STSWorkspaces\SpringApps\com.dbapplications.repositories)
2019-08-30 11:38:34.516 INFO 8596 --- [ main] com.example.demo.Application : No active profile set, falling back to default profiles: default
2019-08-30 11:38:34.830 INFO 8596 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-08-30 11:38:34.844 INFO 8596 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 8ms. Found 0 repository interfaces.
2019-08-30 11:38:35.124 INFO 8596 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-08-30 11:38:35.206 INFO 8596 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2019-08-30 11:38:35.243 INFO 8596 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-08-30 11:38:35.285 INFO 8596 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.3.9.Final}
2019-08-30 11:38:35.286 INFO 8596 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2019-08-30 11:38:35.379 INFO 8596 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2019-08-30 11:38:35.467 INFO 8596 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2019-08-30 11:38:35.595 INFO 8596 --- [ main] o.h.t.schema.internal.SchemaCreatorImpl : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@79d743e6'
2019-08-30 11:38:35.597 INFO 8596 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-08-30 11:38:35.712 INFO 8596 --- [ main] com.example.demo.Application : Started Application in 1.44 seconds (JVM running for 2.333)
2019-08-30 11:38:35.716 INFO 8596 --- [ Thread-3] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2019-08-30 11:38:35.716 INFO 8596 --- [ Thread-3] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed evictData of schema as part of SessionFactory shut-down'
2019-08-30 11:38:35.719 INFO 8596 --- [ Thread-3] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2019-08-30 11:38:35.720 INFO 8596 --- [ Thread-3] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
b) Other Google suggestion was to execute the below command for this project -
mvn clean eclipse:clean eclipse:eclipse
But still the results were same server getting stopped.
c) Someone on Stackoverflow suggested to delete the tomcat folder in .m2, as it might be corrupted. And do update of the
project so that it can take the fresh copy. I did but the results were same.
d) Now I changed the above SpringBoot version to 2.0.0.RELEASE & did the force Maven update of the project.
And now I started the project & it worked. For other project I tried 2.2.7.RELEASE & it also worked.
===============================================================================================
If you see that some dependency is not found or jar not found or some jar is corrupted or some issue with the jar, even if you have added its right dependency in your pom.xml
Then go to your .m2 folder & delete those jar/s & do Maven update(may be forcefully). Once it fetched the jars again then you can see your build getting successful.
===============================================================================================
You configured Swagger in your REST API project in Spring Boot & it is not working even if you did as given on the website & still your Swagger API is not available. Then check if in your project you have used @EnableWebMvc for any file in your project. As this annotation doesn't allow Swagger to be configured by itself & you have to either remove this annotation or configure Swagger manually using below code -
@EnableSwagger2
public class SwaggerEnabler implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry
.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
:
:
:
}
Add above method in the class where you configured your Swagger in your project.
Thanks to : https://stackoverflow.com/questions/43545540/swagger-ui-no-mapping-found-for-http-request for the above
answer
===============================================================================================
You have used Spring Security but don't want Swagger to be part of this security then use below code -
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/v2/api-docs",
"/configuration/ui",
"/swagger-resources/**",
"/configuration/security",
"/swagger-ui.html",
"/webjars/**");
}
Add bove method in the class extending WebSecurityConfigurerAdapter
Thanks to : https://stackoverflow.com/questions/37671125/how-to-configure-spring-security-to-allow-swagger-url-to-be-accessed-without-aut for the above answer