spring boot not using the MongoDB uri in the application.properties - java

In my Spring-boot application, I was trying to use MongoDB which is in AWS instance. For that, I used the host and port number of the AWS Instance to connect it through Spring-boot
application.properties
server.port=8186
# MONGODB (MongoProperties)
#spring.data.mongodb.host=localhost
#spring.data.mongodb.port=27018
#spring.data.mongodb.database=educharge
spring.data.mongodb.uri=mongodb://52.15.64.17:27017/educharge
spring.data.mongodb.database=educharge
when I run the application the program connect to localhost instead of host( 52.15.64.17)
Console output
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.6.RELEASE)
2017-09-16 03:10:08.402 INFO 9536 --- [ restartedMain] c.E.E.EduchargeApiApplication : Starting EduchargeApiApplication on Sankar with PID 9536 (G:\EduchargeAPI\EduchargeAPI\bin started by R Dinesh Kumar in G:\EduchargeAPI\EduchargeAPI)
2017-09-16 03:10:08.402 INFO 9536 --- [ restartedMain] c.E.E.EduchargeApiApplication : No active profile set, falling back to default profiles: default
2017-09-16 03:10:08.408 INFO 9536 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#53b63b22: startup date [Sat Sep 16 03:10:08 IST 2017]; root of context hierarchy
2017-09-16 03:10:09.716 INFO 9536 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8186 (http)
2017-09-16 03:10:09.718 INFO 9536 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2017-09-16 03:10:09.718 INFO 9536 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.16
2017-09-16 03:10:09.750 INFO 9536 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-09-16 03:10:09.750 INFO 9536 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1342 ms
2017-09-16 03:10:09.816 INFO 9536 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-09-16 03:10:09.826 INFO 9536 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'metricsFilter' to: [/*]
2017-09-16 03:10:09.827 INFO 9536 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-09-16 03:10:09.827 INFO 9536 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-09-16 03:10:09.827 INFO 9536 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-09-16 03:10:09.827 INFO 9536 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2017-09-16 03:10:09.827 INFO 9536 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'webRequestLoggingFilter' to: [/*]
2017-09-16 03:10:09.827 INFO 9536 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'applicationContextIdFilter' to: [/*]
2017-09-16 03:10:09.866 INFO 9536 --- [ restartedMain] org.mongodb.driver.cluster : Cluster created with settings {hosts=[127.0.0.1:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=50}
2017-09-16 03:10:10.071 INFO 9536 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#53b63b22: startup date [Sat Sep 16 03:10:08 IST 2017]; root of context hierarchy
2017-09-16 03:10:10.088 INFO 9536 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/Posts/showPost/{postid}],methods=[GET]}" onto public com.Educharge.EduchargeAPI.Model.Post com.Educharge.EduchargeAPI.Controller.PostController.showPost(int)
2017-09-16 03:10:10.089 INFO 9536 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/Posts/{postid}/like/{userid}],methods=[GET]}" onto public com.Educharge.EduchargeAPI.Model.Post com.Educharge.EduchargeAPI.Controller.PostController.likePost(int,int)
2017-09-16 03:10:10.090 INFO 9536 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/Posts/editPost],methods=[PUT]}" onto public com.Educharge.EduchargeAPI.Model.Post com.Educharge.EduchargeAPI.Controller.PostController.editPost(com.Educharge.EduchargeAPI.Model.Post)
2017-09-16 03:10:10.090 INFO 9536 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/Posts/{postid}/comment/{userid}],methods=[PUT]}" onto public com.Educharge.EduchargeAPI.Model.Post com.Educharge.EduchargeAPI.Controller.PostController.commentPost(java.lang.String,int,int)
2017-09-16 03:10:10.090 INFO 9536 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/Posts/createPost],methods=[POST]}" onto public com.Educharge.EduchargeAPI.Model.Post com.Educharge.EduchargeAPI.Controller.PostController.createPost(com.Educharge.EduchargeAPI.Model.Post)
2017-09-16 03:10:10.090 INFO 9536 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/Posts/deletePost/{postid}],methods=[DELETE]}" onto public com.Educharge.EduchargeAPI.Model.Post com.Educharge.EduchargeAPI.Controller.PostController.deletePost(int)
2017-09-16 03:10:10.091 INFO 9536 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/Posts/{postid}/dislike/{userid}],methods=[GET]}" onto public com.Educharge.EduchargeAPI.Model.Post com.Educharge.EduchargeAPI.Controller.PostController.dislikePost(int,int)
2017-09-16 03:10:10.096 INFO 9536 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/Profiles/showProfile/{userid}],methods=[GET]}" onto public com.Educharge.EduchargeAPI.Model.Profile com.Educharge.EduchargeAPI.Controller.ProfileController.showProfile(int)
2017-09-16 03:10:10.097 INFO 9536 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/Profiles/createProfile],methods=[POST]}" onto public com.Educharge.EduchargeAPI.Model.Profile com.Educharge.EduchargeAPI.Controller.ProfileController.addProfile(com.Educharge.EduchargeAPI.Model.Profile)
2017-09-16 03:10:10.097 INFO 9536 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/Profiles/editProfile],methods=[PUT]}" onto public com.Educharge.EduchargeAPI.Model.Profile com.Educharge.EduchargeAPI.Controller.ProfileController.editProfile(com.Educharge.EduchargeAPI.Model.Profile)
2017-09-16 03:10:10.097 INFO 9536 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/Profiles/deleteProfile/{userid}],methods=[DELETE]}" onto public com.Educharge.EduchargeAPI.Model.Profile com.Educharge.EduchargeAPI.Controller.ProfileController.deleteProfile(int)
2017-09-16 03:10:10.101 INFO 9536 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-09-16 03:10:10.102 INFO 9536 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-09-16 03:10:10.118 INFO 9536 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-09-16 03:10:10.118 INFO 9536 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-09-16 03:10:10.141 INFO 9536 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-09-16 03:10:10.319 INFO 9536 --- [ restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/info || /info.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-16 03:10:10.321 INFO 9536 --- [ restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/heapdump || /heapdump.json],methods=[GET],produces=[application/octet-stream]}" onto public void org.springframework.boot.actuate.endpoint.mvc.HeapdumpMvcEndpoint.invoke(boolean,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException,javax.servlet.ServletException
2017-09-16 03:10:10.322 INFO 9536 --- [ restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/mappings || /mappings.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-16 03:10:10.323 INFO 9536 --- [ restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/configprops || /configprops.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-16 03:10:10.324 INFO 9536 --- [ restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/metrics/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint.value(java.lang.String)
2017-09-16 03:10:10.324 INFO 9536 --- [ restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/metrics || /metrics.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-16 03:10:10.325 INFO 9536 --- [ restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/beans || /beans.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-16 03:10:10.325 INFO 9536 --- [ restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/dump || /dump.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-16 03:10:10.326 INFO 9536 --- [ restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/health || /health.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(javax.servlet.http.HttpServletRequest,java.security.Principal)
2017-09-16 03:10:10.329 INFO 9536 --- [ restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/auditevents || /auditevents.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.boot.actuate.endpoint.mvc.AuditEventsMvcEndpoint.findByPrincipalAndAfterAndType(java.lang.String,java.util.Date,java.lang.String)
2017-09-16 03:10:10.330 INFO 9536 --- [ restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/env/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint.value(java.lang.String)
2017-09-16 03:10:10.330 INFO 9536 --- [ restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/env || /env.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-16 03:10:10.332 INFO 9536 --- [ restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/loggers/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.LoggersMvcEndpoint.get(java.lang.String)
2017-09-16 03:10:10.333 INFO 9536 --- [ restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/loggers/{name:.*}],methods=[POST],consumes=[application/vnd.spring-boot.actuator.v1+json || application/json],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.LoggersMvcEndpoint.set(java.lang.String,java.util.Map<java.lang.String, java.lang.String>)
2017-09-16 03:10:10.333 INFO 9536 --- [ restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/loggers || /loggers.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-16 03:10:10.334 INFO 9536 --- [ restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/trace || /trace.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-16 03:10:10.336 INFO 9536 --- [ restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/autoconfig || /autoconfig.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-16 03:10:10.367 INFO 9536 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2017-09-16 03:10:10.434 INFO 9536 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-09-16 03:10:10.443 INFO 9536 --- [ restartedMain] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0
2017-09-16 03:10:10.499 INFO 9536 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8186 (http)
2017-09-16 03:10:10.501 INFO 9536 --- [ restartedMain] c.E.E.EduchargeApiApplication : Started EduchargeApiApplication in 2.166 seconds (JVM running for 4203.36)
2017-09-16 03:10:10.873 INFO 9536 --- [127.0.0.1:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server 127.0.0.1:27017
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.connection.SocketStream.open(SocketStream.java:63) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:113) ~[mongodb-driver-core-3.4.2.jar:na]
at java.lang.Thread.run(Unknown Source) [na:1.8.0_144]
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[na:1.8.0_144]
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) ~[na:1.8.0_144]
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) ~[na:1.8.0_144]
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) ~[na:1.8.0_144]
at java.net.AbstractPlainSocketImpl.connect(Unknown Source) ~[na:1.8.0_144]
at java.net.PlainSocketImpl.connect(Unknown Source) ~[na:1.8.0_144]
at java.net.SocksSocketImpl.connect(Unknown Source) ~[na:1.8.0_144]
at java.net.Socket.connect(Unknown Source) ~[na:1.8.0_144]
at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:57) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.connection.SocketStream.open(SocketStream.java:58) ~[mongodb-driver-core-3.4.2.jar:na]
... 3 common frames omitted
and prints the Exception opening socket
Is there any other way to connect the remote MongoDB host server ?

If you are connecting to your remote Mongodb instance, have you checked 52.15.64.17 is pingable for you?
Based on Connecting to a MongoDB database:
spring.data.mongodb.uri=mongodb://user:secret#mongo1.example.com:12345,mongo2.example.com:23456/test
Alternatively, You can mute the Springboot AutoConfiguration for mongoDB:
#SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})

I had a similar problem using MongoDB and Embedded MongoDB, each one configured in a different spring profile.
In my case, the Spring was ignoring the MongoDB URI from my "production" profile and it always started the embedded mongoDb.
The problem was the EmbeddedMongoAutoConfiguration enabled. So, you can disable the Embedded MongoDB in a specific profile using the properties:
spring:
autoconfigure:
exclude: org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration

Related

How to start spring boot application for the sake of integration testing [duplicate]

I have a JUnit Test that starts my spring boot appcliation (Application.java).
#RunWith(SpringRunner.class)
#SpringBootTest(classes = Application.class)
public class AppclaitionTest {
#Test
public void contextLoads(){
Application.main(new String[]{});
}
}
If I run the JUnit test, Application is successfully starting up, but not accessible through url
Application Logs:
2017-06-16 12:18:07.918 INFO 207028 --- [ main] com.chandu.test.AppclaitionTest : Started AppclaitionTest in 1.927 seconds (JVM running for 2.458)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.3.RELEASE)
2017-06-16 12:18:08.012 INFO 207028 --- [ main] com.test.app.Application : Starting Application on IVL-WS39 with PID 207028 (started by Bhanuchandar.Challa in D:\Jars\SpringJDBCMySQL)
2017-06-16 12:18:08.012 INFO 207028 --- [ main] com.test.app.Application : No active profile set, falling back to default profiles: default
2017-06-16 12:18:08.012 INFO 207028 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#3f1ddac2: startup date [Fri Jun 16 12:18:08 IST 2017]; root of context hierarchy
2017-06-16 12:18:08.402 INFO 207028 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-06-16 12:18:08.417 INFO 207028 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2017-06-16 12:18:08.417 INFO 207028 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.14
2017-06-16 12:18:08.526 INFO 207028 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-06-16 12:18:08.526 INFO 207028 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 514 ms
2017-06-16 12:18:08.636 INFO 207028 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-06-16 12:18:08.636 INFO 207028 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-06-16 12:18:08.636 INFO 207028 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-06-16 12:18:08.636 INFO 207028 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-06-16 12:18:08.636 INFO 207028 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2017-06-16 12:18:08.933 INFO 207028 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#3f1ddac2: startup date [Fri Jun 16 12:18:08 IST 2017]; root of context hierarchy
2017-06-16 12:18:08.933 INFO 207028 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/getRowCount]}" onto public java.lang.Integer com.test.app.controller.TestController.getRowCount(java.lang.String)
2017-06-16 12:18:08.949 INFO 207028 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/process]}" onto public java.lang.String com.test.app.controller.TestController.processRequest()
2017-06-16 12:18:08.949 INFO 207028 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-06-16 12:18:08.949 INFO 207028 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-06-16 12:18:08.964 INFO 207028 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-06-16 12:18:08.964 INFO 207028 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-06-16 12:18:08.980 INFO 207028 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-06-16 12:18:09.105 INFO 207028 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-06-16 12:18:09.151 INFO 207028 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-06-16 12:18:09.151 INFO 207028 --- [ main] com.test.app.Application : Started Application in 1.186 seconds (JVM running for 3.689)
When I tried to access the application through url 'http://localhost:8080/process', It says Site can't be reached.
Why would you do such thing? This should be a unit test and the flow of the test should be the following:
Start the application -> Call your controller endpoint -> assert that a specific text/element on that page is present -> Shut down the application.
Start the application : #RunWith(SpringRunner.class) doing this for you, no need to start is manually.
Shut down the application : At the end of your test class Spring boot does this for you (That's why you cant access your app in the browser)
For further help please see my answer here: How to test (rest) enpoints
By default, in #SpringBootTest annotation the field webEnvironment is set to WebEnvironment.MOCK
Therefore, Tomcat does not start.
You can set this field to WebEnvironment.DEFINED_PORT/RANDOM_PORT.
After this, Tomcat will be running.
#SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class MyTestClass {
...
...
...
}

Spring Boot Not Deploying WAR From IntelliJ

I was trying to deploy my first Spring Boot application to WAR file but it's not working. There is no error showing but also not finding any WAR file.
I have followed all the steps found on Spring Boot documentation and all over StackOverflow. Here are these:
Step 1: I have extended SpringBootServletInitializer
#SpringBootApplication
public class SpringBoot1Application extends SpringBootServletInitializer
{
public static void main(String[] args) throws Exception
{
SpringApplication.run(SpringBoot1Application.class, args);
}
}
Step 2: Added apply plugin: 'war' and dependencies in the build.gradle file
buildscript {
ext {
springBootVersion = '2.0.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
group = 'com.ranadepto'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-web')
runtime('org.springframework.boot:spring-boot-devtools')
runtime('mysql:mysql-connector-java')
testCompile('org.springframework.boot:spring-boot-starter-test')
provided 'org.springframework.boot:spring-boot-starter-tomcat'
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
}
war {
baseName = 'SpringBoot1'
}
I am also including console output messages:
:: Spring Boot :: (v2.0.3.RELEASE)
2018-07-06 20:50:49.322 INFO 3489 --- [ restartedMain] c.r.SpringBoot1.SpringBoot1Application : Starting SpringBoot1Application on Rana-Depto-MacBook-Pro.local with PID 3489 (/Users/ranadepto/Desktop/SpringBoot1/out/production/classes started by ranadepto in /Users/ranadepto/Desktop/SpringBoot1)
2018-07-06 20:50:49.324 INFO 3489 --- [ restartedMain] c.r.SpringBoot1.SpringBoot1Application : No active profile set, falling back to default profiles: default
2018-07-06 20:50:49.375 INFO 3489 --- [ restartedMain] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#7acf6bce: startup date [Fri Jul 06 20:50:49 BDT 2018]; root of context hierarchy
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1 (file:/Users/ranadepto/.gradle/caches/modules-2/files-2.1/org.springframework/spring-core/5.0.7.RELEASE/54b731178d81e66eca9623df772ff32718208137/spring-core-5.0.7.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2018-07-06 20:50:50.215 INFO 3489 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$f69149ff] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-07-06 20:50:50.461 INFO 3489 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2018-07-06 20:50:50.476 INFO 3489 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-07-06 20:50:50.477 INFO 3489 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.31
2018-07-06 20:50:50.480 INFO 3489 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/Users/ranadepto/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]
2018-07-06 20:50:50.527 INFO 3489 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-07-06 20:50:50.527 INFO 3489 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1157 ms
2018-07-06 20:50:50.612 INFO 3489 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2018-07-06 20:50:50.615 INFO 3489 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-07-06 20:50:50.615 INFO 3489 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-07-06 20:50:50.615 INFO 3489 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-07-06 20:50:50.615 INFO 3489 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-07-06 20:50:50.710 INFO 3489 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2018-07-06 20:50:50.841 INFO 3489 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2018-07-06 20:50:50.866 INFO 3489 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2018-07-06 20:50:50.873 INFO 3489 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2018-07-06 20:50:50.908 INFO 3489 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate Core {5.2.17.Final}
2018-07-06 20:50:50.909 INFO 3489 --- [ restartedMain] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2018-07-06 20:50:50.931 INFO 3489 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2018-07-06 20:50:50.995 INFO 3489 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
2018-07-06 20:50:51.305 INFO 3489 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-07-06 20:50:51.523 INFO 3489 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-07-06 20:50:51.682 INFO 3489 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#7acf6bce: startup date [Fri Jul 06 20:50:49 BDT 2018]; root of context hierarchy
2018-07-06 20:50:51.700 WARN 3489 --- [ restartedMain] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2018-07-06 20:50:51.722 INFO 3489 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/reports],methods=[GET]}" onto public java.util.List<com.ranadepto.SpringBoot1.ReportModel> com.ranadepto.SpringBoot1.ReportController.getAllReports()
2018-07-06 20:50:51.723 INFO 3489 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/reports/{id}],methods=[GET]}" onto public com.ranadepto.SpringBoot1.ReportModel com.ranadepto.SpringBoot1.ReportController.getReportById(java.lang.String)
2018-07-06 20:50:51.724 INFO 3489 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/reports],methods=[POST]}" onto public com.ranadepto.SpringBoot1.ReportModel com.ranadepto.SpringBoot1.ReportController.createReport(com.ranadepto.SpringBoot1.ReportModel)
2018-07-06 20:50:51.724 INFO 3489 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/reports/{id}],methods=[PUT]}" onto public com.ranadepto.SpringBoot1.ReportModel com.ranadepto.SpringBoot1.ReportController.updateReport(java.lang.String,com.ranadepto.SpringBoot1.ReportModel)
2018-07-06 20:50:51.724 INFO 3489 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/reports/{id}],methods=[DELETE]}" onto public org.springframework.http.ResponseEntity<?> com.ranadepto.SpringBoot1.ReportController.deleteReport(java.lang.String)
2018-07-06 20:50:51.726 INFO 3489 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-07-06 20:50:51.726 INFO 3489 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-07-06 20:50:51.746 INFO 3489 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-07-06 20:50:51.746 INFO 3489 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-07-06 20:50:51.921 INFO 3489 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2018-07-06 20:50:51.942 INFO 3489 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-07-06 20:50:51.943 INFO 3489 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure
2018-07-06 20:50:51.947 INFO 3489 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2018-07-06 20:50:51.972 INFO 3489 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-07-06 20:50:51.976 INFO 3489 --- [ restartedMain] c.r.SpringBoot1.SpringBoot1Application : Started SpringBoot1Application in 2.93 seconds (JVM running for 3.809)
And finally this is a screenshot of IntelliJ directory hierarchy:
I have been spending for hour on debugging and searching on the web and finally ended up here with a question. Please help me out with how can I get rid of this.

Spring Boot - When I call API, its gives 404 error

I have created a spring boot application. When I deploy the jar file in embedded tomcat and called the test API it gives 404 error. May I know why it is giving the error?
Main class
package com.telematics.fleet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
#SpringBootApplication
#ComponentScan(basePackages={"com.telematics.fleet.controller", "com.telematics.fleet.repository",
"com.telematics.fleet.service","com.telematics.fleet.utility"})
public class TelematicsFleetApplication
{
public static void main(String[] args)
{
SpringApplication.run(TelematicsFleetApplication.class, args);
}
}
Controller class
package com.telematics.fleet.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
#RestController
#RequestMapping("/app")
public class FleetAppController
{
#RequestMapping(value="/test", method=RequestMethod.GET)
public String test()
{
System.out.println("Called test API");
return "Success";
}
}
Console
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/dell/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/dell/.m2/repository/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
The Class-Path manifest attribute in C:\Users\dell\.m2\repository\com\mchange\c3p0\0.9.5.2\c3p0-0.9.5.2.jar referenced one or more files that do not exist: file:/C:/Users/dell/.m2/repository/com/mchange/c3p0/0.9.5.2/mchange-commons-java-0.2.11.jar
08:22:29.726 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
08:22:29.738 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-starter/target/classes/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot/target/classes/, /spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/]
08:22:29.739 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/C:/Malya/Git_Homes/telematics-fleet/target/classes/]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.0.RELEASE)
2018-03-22 08:22:31.881 INFO 252 --- [ restartedMain] c.t.fleet.TelematicsFleetApplication : Starting TelematicsFleetApplication on admin with PID 252 (C:\Malya\Git_Homes\telematics-fleet\target\classes started by dell in C:\Malya\Git_Homes\telematics-fleet)
2018-03-22 08:22:31.889 INFO 252 --- [ restartedMain] c.t.fleet.TelematicsFleetApplication : No active profile set, falling back to default profiles: default
2018-03-22 08:22:32.280 INFO 252 --- [ restartedMain] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#795b4bba: startup date [Thu Mar 22 08:22:32 IST 2018]; root of context hierarchy
2018-03-22 08:22:47.336 INFO 252 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$8c439cf8] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-22 08:22:51.865 INFO 252 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2018-03-22 08:22:52.015 INFO 252 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-03-22 08:22:52.016 INFO 252 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.28
2018-03-22 08:22:52.076 INFO 252 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_162\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_162/bin/server;C:/Program Files/Java/jre1.8.0_162/bin;C:/Program Files/Java/jre1.8.0_162/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;c:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Git\cmd;C:\Program Files (x86)\Skype\Phone\;C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\ARM GCC\bin\;C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\eclipse\jre\bin\;C:\Program Files (x86)\sbt\bin;C:\modeltech64_10.2c\win64;C:\Program Files (x86)\CodeBlocks\MinGW\bin;C:\Program Files (x86)\CodeBlocks\MinGW;C:\myrWork\ztex-160513\sp3anTest\aes220_win_files_160502-1\aes220_win_files\DLL;C:\myrWork\ztex-160513\sp3anTest\aes220_win_files_160502-1\aes220_win_files\libs\MS32;C:\myrWork\eMMCModel\ss_emmc\eMMC_vip\sdio\rlm\win_64;C:\workspace\eMMCModel\ss_emmc\eMMC_vip\sdio\sv\examples\sim;C:\Malya\tool\sts-bundle\sts-3.9.2.RELEASE;;.]
2018-03-22 08:22:52.790 INFO 252 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-03-22 08:22:52.791 INFO 252 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 20525 ms
2018-03-22 08:23:00.377 INFO 252 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2018-03-22 08:23:00.407 INFO 252 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-03-22 08:23:00.408 INFO 252 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-03-22 08:23:00.409 INFO 252 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-03-22 08:23:00.410 INFO 252 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-03-22 08:23:00.411 INFO 252 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpTraceFilter' to: [/*]
2018-03-22 08:23:00.412 INFO 252 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'webMvcMetricsFilter' to: [/*]
2018-03-22 08:23:01.619 INFO 252 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2018-03-22 08:23:03.674 INFO 252 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2018-03-22 08:23:04.327 INFO 252 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2018-03-22 08:23:04.469 INFO 252 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2018-03-22 08:23:05.269 INFO 252 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate Core {5.2.14.Final}
2018-03-22 08:23:05.284 INFO 252 --- [ restartedMain] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2018-03-22 08:23:05.721 INFO 252 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2018-03-22 08:23:08.342 INFO 252 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2018-03-22 08:23:16.185 INFO 252 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-03-22 08:23:34.747 INFO 252 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#795b4bba: startup date [Thu Mar 22 08:22:32 IST 2018]; root of context hierarchy
2018-03-22 08:23:36.160 WARN 252 --- [ restartedMain] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2018-03-22 08:23:37.239 INFO 252 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/app/test],methods=[GET]}" onto public java.lang.String com.telematics.fleet.controller.FleetAppController.test()
2018-03-22 08:23:37.380 INFO 252 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-03-22 08:23:37.383 INFO 252 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-03-22 08:23:38.325 INFO 252 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-22 08:23:38.326 INFO 252 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-22 08:23:39.279 INFO 252 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-22 08:23:40.156 WARN 252 --- [ restartedMain] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
2018-03-22 08:23:46.453 INFO 252 --- [ restartedMain] org.quartz.impl.StdSchedulerFactory : Using default implementation for ThreadExecutor
2018-03-22 08:23:46.581 INFO 252 --- [ restartedMain] org.quartz.core.SchedulerSignalerImpl : Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
2018-03-22 08:23:46.582 INFO 252 --- [ restartedMain] org.quartz.core.QuartzScheduler : Quartz Scheduler v.2.3.0 created.
2018-03-22 08:23:46.588 INFO 252 --- [ restartedMain] org.quartz.simpl.RAMJobStore : RAMJobStore initialized.
2018-03-22 08:23:46.593 INFO 252 --- [ restartedMain] org.quartz.core.QuartzScheduler : Scheduler meta-data: Quartz Scheduler (v2.3.0) 'quartzScheduler' with instanceId 'NON_CLUSTERED'
Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
NOT STARTED.
Currently in standby mode.
Number of jobs executed: 0
Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.
2018-03-22 08:23:46.595 INFO 252 --- [ restartedMain] org.quartz.impl.StdSchedulerFactory : Quartz scheduler 'quartzScheduler' initialized from an externally provided properties instance.
2018-03-22 08:23:46.595 INFO 252 --- [ restartedMain] org.quartz.impl.StdSchedulerFactory : Quartz scheduler version: 2.3.0
2018-03-22 08:23:46.596 INFO 252 --- [ restartedMain] org.quartz.core.QuartzScheduler : JobFactory set to: org.springframework.boot.autoconfigure.quartz.AutowireCapableBeanJobFactory#629a27c7
2018-03-22 08:23:47.067 INFO 252 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2018-03-22 08:23:47.271 INFO 252 --- [ restartedMain] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped "{[/actuator/health],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.String>)
2018-03-22 08:23:47.274 INFO 252 --- [ restartedMain] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped "{[/actuator/info],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.String>)
2018-03-22 08:23:47.279 INFO 252 --- [ restartedMain] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped "{[/actuator],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto protected java.util.Map<java.lang.String, java.util.Map<java.lang.String, org.springframework.boot.actuate.endpoint.web.Link>> org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping.links(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-03-22 08:23:48.079 INFO 252 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-03-22 08:23:48.086 INFO 252 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure
2018-03-22 08:23:48.130 INFO 252 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2018-03-22 08:23:48.207 INFO 252 --- [ restartedMain] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483647
2018-03-22 08:23:48.208 INFO 252 --- [ restartedMain] o.s.s.quartz.SchedulerFactoryBean : Starting Quartz Scheduler now
2018-03-22 08:23:48.209 INFO 252 --- [ restartedMain] org.quartz.core.QuartzScheduler : Scheduler quartzScheduler_$_NON_CLUSTERED started.
2018-03-22 08:23:48.464 INFO 252 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-03-22 08:23:48.488 INFO 252 --- [ restartedMain] c.t.fleet.TelematicsFleetApplication : Started TelematicsFleetApplication in 78.687 seconds (JVM running for 81.635)
2018-03-22 08:24:55.653 INFO 252 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-03-22 08:24:55.654 INFO 252 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2018-03-22 08:24:55.755 INFO 252 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 101 ms
POSTMAN Response
{
"timestamp": "2018-03-22T03:06:40.138+0000",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/telematics-fleet/app/test"
}
Properties file
spring.jpa.hibernate.ddl-auto=update
spring.jpa.generate-ddl=true
spring.datasource.url=jdbc:mysql://localhost:3306/db_example
spring.datasource.username=springuser
spring.datasource.password=ThePassword
In the console server is running fine but i am getting 404 error when trying to access the api's
There are two important points to keep in mind while deploying a SpringBoot application to a container :
1.Starting point of application: If you are deploying a SprinBoot application to any servlet container(like Tomcat) your starter class must extend SpringBootServletInitializer, so that the container can find the starting point of your application
#SpringBootApplication
public class TelematicsFleetApplication extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(TelematicsFleetApplication .class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(TelematicsFleetApplication .class, args);
}
}
After successful deployment on Tomcat you should prefix your application name before all resource URLs.
Example : localhost:8080/Application_Name/app/test
Extra tip: After Spring 4.3 you can replace #RequestMapping(method = RequestMethod.GET) by #GetMapping
Example : #Getmapping("/test")
You should change your controller to:
#RestController
#RequestMapping("/telematics-fleet/app")
public class FleetAppController
{
#RequestMapping(value="/test", method=RequestMethod.GET)
public String test()
{
System.out.println("Called test API");
return "Success";
}
}
The current call does not point to correct resource.
Note the log states that your server was started and pointing to / as root and not /telematics-fleet.
The other thing you could do is keep your controller as it is and add a new property in application.properties as:
server.contextPath=/telematics-fleet
Your postman requesting the path--- "path": "/telematics-fleet/app/test" but your controller the path should be "path": "/app/test" . So there is a missmatch.
Try removing context
http://localhost:8080/app/test
If you running it using spring boot plugin, and haven't configured context in meta file, spring boot run on default context
The project name is not automatically added to the context path in Spring Boot, it is / by default. If you do want to add it, set the following in your .properties file:
server.servlet.contextPath=/telematics-fleet
Or for pre-2.0 versions of Spring Boot:
server.contextPath=/telematics-fleet
If not, then just remove that part from your request, hitting /app/test directly.
In my project, it was because of the missing dependency in the pom.
spring-boot-starter-web
Look for Servlet dispatcherServlet mapped to [/] in the logs, if it is not there, it means the required dependencies are missing
Had a similar issue. For me, the project name in Eclipse was different from the one that was mentioned in the application.properties.
renaming the eclipse project to the same as the one in application.properties solved the issue

Can't add camunda-bom to springboot project

I'm trying to create a camunda application with springboot, but i need to use Spin Json Node, and when i add the dependencies to the pom.xml it gives me this error when i run project as java application:
org.springframework.context.ApplicationContextException: Unable to
start embedded container; nested exception is
org.springframework.boot.context.embedded.EmbeddedServletContainerException:
Unable to start embedded Tomcat at
org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137)
~[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE] at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
~[spring-context-4.3.11.RELEASE.jar:4.3.11.RELEASE] at
org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
~[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE] at
org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE] at
org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE] at
br.com.ntconsult.camundaProject.app.CamundaSpringbootApplication.main(CamundaSpringbootApplication.java:9)
[classes/:na] Caused by:
org.springframework.boot.context.embedded.EmbeddedServletContainerException:
Unable to start embedded Tomcat at
org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:123)
~[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE] at
org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.(TomcatEmbeddedServletContainer.java:84)
~[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE] at
org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:554)
~[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE] at
org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:179)
~[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE] at
org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164)
~[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE] at
org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134)
~[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE] ... 8 common frames
omitted Caused by: org.apache.catalina.LifecycleException: Failed to
start component [StandardServer[-1]] at
org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
~[tomcat-embed-core-8.5.20.jar:8.5.20] at
org.apache.catalina.startup.Tomcat.start(Tomcat.java:367)
~[tomcat-embed-core-8.5.20.jar:8.5.20] at
org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:99)
~[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE] ... 13 common frames
omitted Caused by: org.apache.catalina.LifecycleException: Failed to
start component [StandardService[Tomcat]] at
org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
~[tomcat-embed-core-8.5.20.jar:8.5.20] at
org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:793)
~[tomcat-embed-core-8.5.20.jar:8.5.20] at
org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
~[tomcat-embed-core-8.5.20.jar:8.5.20] ... 15 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Failed to start
component [StandardEngine[Tomcat]] at
org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
~[tomcat-embed-core-8.5.20.jar:8.5.20] at
org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
~[tomcat-embed-core-8.5.20.jar:8.5.20] at
org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
~[tomcat-embed-core-8.5.20.jar:8.5.20] ... 17 common frames omitted
Caused by: org.apache.catalina.LifecycleException: A child container
failed during start at
org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:947)
~[tomcat-embed-core-8.5.20.jar:8.5.20] at
org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
~[tomcat-embed-core-8.5.20.jar:8.5.20] at
org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
~[tomcat-embed-core-8.5.20.jar:8.5.20] ... 19 common frames omitted
If i remove the camunda-bom from the dependencyManagement in pom.xml everything works, but i can't use things like spin json node.
I created a simple project with this error in github: https://github.com/jradesenv/camunda-springboot
The project you provided on GitHub works perfectly fine on my end and runs as expected. You cut off part of the stacktrace, so I cannot see the root cause. Something stops Tomcat from starting - probably an already used port?
PS: We released a preview of the upcoming Spring Boot archetype yesterday: https://github.com/camunda/camunda-archetypes/tree/master/camunda-archetype-spring-boot/ - might be a good starting point too.
FYI my console (I just pulled the code and run it):
____ _ ____ ____ __ __
/ ___| __ _ _ __ ___ _ _ _ __ __| | __ _ | __ )| _ \| \/ |
| | / _` | '_ ` _ \| | | | '_ \ / _` |/ _` | | _ \| |_) | |\/| |
| |__| (_| | | | | | | |_| | | | | (_| | (_| | | |_) | __/| | | |
\____/\__,_|_| |_| |_|\__,_|_| |_|\__,_|\__,_| |____/|_| |_| |_|
Spring-Boot: (v1.5.7.RELEASE)
Camunda BPM: (v7.8.0-alpha6)
Camunda BPM Spring Boot Starter: (v2.3.0-alpha1)
2017-11-22 09:12:24.931 INFO 13404 --- [ main] b.c.n.c.a.CamundaSpringbootApplication : Starting CamundaSpringbootApplication on LAPTOP-LFHA6NM6 with PID 13404 (C:\Temp\camunda-springboot-support\target\classes started by ruecker in C:\Temp\camunda-springboot-support)
2017-11-22 09:12:24.954 INFO 13404 --- [ main] b.c.n.c.a.CamundaSpringbootApplication : No active profile set, falling back to default profiles: default
2017-11-22 09:12:25.052 INFO 13404 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#37918c79: startup date [Wed Nov 22 09:12:25 CET 2017]; root of context hierarchy
2017-11-22 09:12:26.624 INFO 13404 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2017-11-22 09:12:27.830 INFO 13404 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-11-22 09:12:27.854 INFO 13404 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2017-11-22 09:12:27.856 INFO 13404 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.20
2017-11-22 09:12:28.079 INFO 13404 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-11-22 09:12:28.080 INFO 13404 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3033 ms
2017-11-22 09:12:28.522 INFO 13404 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-11-22 09:12:28.567 INFO 13404 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-11-22 09:12:28.568 INFO 13404 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-11-22 09:12:28.568 INFO 13404 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-11-22 09:12:28.568 INFO 13404 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2017-11-22 09:12:29.118 INFO 13404 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#37918c79: startup date [Wed Nov 22 09:12:25 CET 2017]; root of context hierarchy
2017-11-22 09:12:29.232 INFO 13404 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-11-22 09:12:29.234 INFO 13404 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-11-22 09:12:29.264 INFO 13404 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Root mapping to handler of type [class org.springframework.web.servlet.mvc.ParameterizableViewController]
2017-11-22 09:12:29.287 INFO 13404 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-11-22 09:12:29.288 INFO 13404 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-11-22 09:12:29.288 INFO 13404 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/lib/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-11-22 09:12:29.288 INFO 13404 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/api/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-11-22 09:12:29.289 INFO 13404 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/app/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-11-22 09:12:29.359 INFO 13404 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-11-22 09:12:29.870 INFO 13404 --- [ main] org.camunda.bpm.spring.boot : STARTER-SB040 Setting up jobExecutor with corePoolSize=3, maxPoolSize:10
2017-11-22 09:12:29.891 INFO 13404 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'camundaTaskExecutor'
2017-11-22 09:12:30.101 INFO 13404 --- [ main] org.camunda.bpm.engine.cfg : ENGINE-12003 Plugin 'CompositeProcessEnginePlugin[genericPropertiesConfiguration, camundaProcessEngineConfiguration, camundaDatasourceConfiguration, camundaJobConfiguration, camundaHistoryConfiguration, camundaMetricsConfiguration, camundaAuthorizationConfiguration, camundaDeploymentConfiguration, failedJobConfiguration]' activated on process engine 'default'
2017-11-22 09:12:32.841 INFO 13404 --- [ main] org.camunda.bpm.spring.boot : STARTER-SB021 Auto-Deploying resources: []
2017-11-22 09:12:36.911 INFO 13404 --- [ main] org.camunda.bpm.engine.persistence : ENGINE-03016 Performing database operation 'create' on component 'engine' with resource 'org/camunda/bpm/engine/db/create/activiti.h2.create.engine.sql'
2017-11-22 09:12:36.965 INFO 13404 --- [ main] org.camunda.bpm.engine.persistence : ENGINE-03016 Performing database operation 'create' on component 'history' with resource 'org/camunda/bpm/engine/db/create/activiti.h2.create.history.sql'
2017-11-22 09:12:36.993 INFO 13404 --- [ main] org.camunda.bpm.engine.persistence : ENGINE-03016 Performing database operation 'create' on component 'identity' with resource 'org/camunda/bpm/engine/db/create/activiti.h2.create.identity.sql'
2017-11-22 09:12:37.024 INFO 13404 --- [ main] org.camunda.bpm.engine.persistence : ENGINE-03016 Performing database operation 'create' on component 'case.engine' with resource 'org/camunda/bpm/engine/db/create/activiti.h2.create.case.engine.sql'
2017-11-22 09:12:37.037 INFO 13404 --- [ main] org.camunda.bpm.engine.persistence : ENGINE-03016 Performing database operation 'create' on component 'case.history' with resource 'org/camunda/bpm/engine/db/create/activiti.h2.create.case.history.sql'
2017-11-22 09:12:37.045 INFO 13404 --- [ main] org.camunda.bpm.engine.persistence : ENGINE-03016 Performing database operation 'create' on component 'decision.engine' with resource 'org/camunda/bpm/engine/db/create/activiti.h2.create.decision.engine.sql'
2017-11-22 09:12:37.068 INFO 13404 --- [ main] org.camunda.bpm.engine.persistence : ENGINE-03016 Performing database operation 'create' on component 'decision.history' with resource 'org/camunda/bpm/engine/db/create/activiti.h2.create.decision.history.sql'
2017-11-22 09:12:37.159 INFO 13404 --- [ main] org.camunda.bpm.engine.persistence : ENGINE-03067 No history level property found in database
2017-11-22 09:12:37.159 INFO 13404 --- [ main] org.camunda.bpm.engine.persistence : ENGINE-03065 Creating historyLevel property in database for level: HistoryLevelFull(name=full, id=3)
2017-11-22 09:12:37.171 INFO 13404 --- [ main] org.camunda.bpm.engine : ENGINE-00001 Process Engine default created.
2017-11-22 09:12:37.370 INFO 13404 --- [ main] o.c.b.s.b.s.w.f.LazyInitRegistration : lazy initialized org.camunda.bpm.spring.boot.starter.webapp.filter.LazyProcessEnginesFilter#4e25e00f
2017-11-22 09:12:37.470 INFO 13404 --- [ main] o.c.b.s.b.s.w.f.LazyInitRegistration : lazy initialized org.camunda.bpm.spring.boot.starter.webapp.filter.LazySecurityFilter#2097d719
2017-11-22 09:12:37.808 INFO 13404 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-11-22 09:12:37.934 INFO 13404 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-11-22 09:12:37.944 INFO 13404 --- [ main] org.camunda.bpm.engine.jobexecutor : ENGINE-14014 Starting up the JobExecutor[org.camunda.bpm.engine.spring.components.jobexecutor.SpringJobExecutor].
2017-11-22 09:12:37.947 INFO 13404 --- [ main] b.c.n.c.a.CamundaSpringbootApplication : Started CamundaSpringbootApplication in 13.493 seconds (JVM running for 14.344)
2017-11-22 09:12:37.949 INFO 13404 --- [ingJobExecutor]] org.camunda.bpm.engine.jobexecutor : ENGINE-14018 JobExecutor[org.camunda.bpm.engine.spring.components.jobexecutor.SpringJobExecutor] starting to acquire jobs

spring boot file upload is not working

i am very new to spring boot, i am trying to upload a file i get this error :
> Whitelabel Error Page
>
> This application has no explicit mapping for /error, so you are seeing
> this as a fallback.
>
> Sun Jan 22 21:05:28 MSK 2017
> There was an unexpected error (type=Not Found, status=404).
> No message available
this is my Application.java file :
package com.theligue.webservice;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import com.theligue.webservice.storage.StorageProperties;
import com.theligue.webservice.storage.StorageService;
#SpringBootApplication
#EnableConfigurationProperties(StorageProperties.class)
public class Application {
public static void main(String[] args) {
System.out.println("00000000000000000000000000000000000000000000");
SpringApplication.run(Application.class, args);
System.out.println("11111111111111111111111111111111111111");
}
#Bean
CommandLineRunner init(StorageService storageService) {
System.out.println("222222222222222222222222222222222222222222222222");
return (args) -> {
storageService.deleteAll();
storageService.init();
};
}
}
and this is the File uploader controller File :
package com.theligue.webservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.theligue.webservice.storage.StorageFileNotFoundException;
import com.theligue.webservice.storage.StorageService;
import java.io.IOException;
import java.util.stream.Collectors;
#Controller
#RequestMapping("/api")
public class FileUploadController {
private final StorageService storageService;
#Autowired
public FileUploadController(StorageService storageService) {
System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
this.storageService = storageService;
}
#GetMapping("/")
public String listUploadedFiles(Model model) throws IOException {
System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
model.addAttribute("files", storageService
.loadAll()
.map(path ->
MvcUriComponentsBuilder
.fromMethodName(FileUploadController.class, "serveFile", path.getFileName().toString())
.build().toString())
.collect(Collectors.toList()));
System.out.println("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
return "uploadForm";
}
#GetMapping("/files/{filename:.+}")
#ResponseBody
public ResponseEntity<Resource> serveFile(#PathVariable String filename) {
Resource file = storageService.loadAsResource(filename);
return ResponseEntity
.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\""+file.getFilename()+"\"")
.body(file);
}
#PostMapping("/")
public String handleFileUpload(#RequestParam("file") MultipartFile file,
RedirectAttributes redirectAttributes) {
storageService.store(file);
redirectAttributes.addFlashAttribute("message",
"You successfully uploaded " + file.getOriginalFilename() + "!");
return "redirect:/";
}
#ExceptionHandler(StorageFileNotFoundException.class)
public ResponseEntity handleStorageFileNotFound(StorageFileNotFoundException exc) {
return ResponseEntity.notFound().build();
}
}
this is the console output when i hit localhost:8080/
00000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.4.3.RELEASE)
2017-01-22 21:05:08.319 INFO 1572 --- [ restartedMain] com.theligue.webservice.Application : Starting Application on DESKTOP-M1QNJT9 with PID 1572 (started by Mohammad Taha in C:\Users\Mohammad Taha\workspace\theLigue\LigueWebServices)
2017-01-22 21:05:08.322 INFO 1572 --- [ restartedMain] com.theligue.webservice.Application : No active profile set, falling back to default profiles: default
2017-01-22 21:05:08.637 INFO 1572 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#1c13f3d5: startup date [Sun Jan 22 21:05:08 MSK 2017]; root of context hierarchy
2017-01-22 21:05:11.743 INFO 1572 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-01-22 21:05:11.760 INFO 1572 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service Tomcat
2017-01-22 21:05:11.763 INFO 1572 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.6
2017-01-22 21:05:11.949 INFO 1572 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-01-22 21:05:11.949 INFO 1572 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3315 ms
2017-01-22 21:05:12.198 INFO 1572 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-01-22 21:05:12.202 INFO 1572 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-01-22 21:05:12.203 INFO 1572 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-01-22 21:05:12.203 INFO 1572 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-01-22 21:05:12.203 INFO 1572 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2017-01-22 21:05:12.317 WARN 1572 --- [ restartedMain] f.a.AutowiredAnnotationBeanPostProcessor : Autowired annotation should only be used on methods with parameters: public java.util.Collection com.theligue.webservice.service.PlayerService.getFakeDataObject()
222222222222222222222222222222222222222222222222
2017-01-22 21:05:12.950 INFO 1572 --- [ restartedMain] org.mongodb.driver.cluster : Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2017-01-22 21:05:13.013 INFO 1572 --- [localhost:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:1, serverValue:4}] to localhost:27017
2017-01-22 21:05:13.015 INFO 1572 --- [localhost:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 4, 1]}, minWireVersion=0, maxWireVersion=5, maxDocumentSize=16777216, roundTripTimeNanos=568071}
2017-01-22 21:05:13.334 INFO 1572 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#1c13f3d5: startup date [Sun Jan 22 21:05:08 MSK 2017]; root of context hierarchy
2017-01-22 21:05:13.554 INFO 1572 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/],methods=[GET]}" onto public java.lang.String com.theligue.webservice.FileUploadController.listUploadedFiles(org.springframework.ui.Model) throws java.io.IOException
2017-01-22 21:05:13.555 INFO 1572 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/files/{filename:.+}],methods=[GET]}" onto public org.springframework.http.ResponseEntity<org.springframework.core.io.Resource> com.theligue.webservice.FileUploadController.serveFile(java.lang.String)
2017-01-22 21:05:13.556 INFO 1572 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/],methods=[POST]}" onto public java.lang.String com.theligue.webservice.FileUploadController.handleFileUpload(org.springframework.web.multipart.MultipartFile,org.springframework.web.servlet.mvc.support.RedirectAttributes)
2017-01-22 21:05:13.559 INFO 1572 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-01-22 21:05:13.560 INFO 1572 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-01-22 21:05:13.605 INFO 1572 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-01-22 21:05:13.605 INFO 1572 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-01-22 21:05:13.655 INFO 1572 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-01-22 21:05:14.328 INFO 1572 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2017-01-22 21:05:14.408 INFO 1572 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-01-22 21:05:14.489 INFO 1572 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-01-22 21:05:14.498 INFO 1572 --- [ restartedMain] com.theligue.webservice.Application : Started Application in 6.679 seconds (JVM running for 7.413)
11111111111111111111111111111111111111
2017-01-22 21:05:28.908 INFO 1572 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2017-01-22 21:05:28.908 INFO 1572 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2017-01-22 21:05:28.930 INFO 1572 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet
i noticed that it dose not go to listUpdatedFiles function inside the file upload controller .
You have
#RequestMapping("/api")
public class FileUploadController {
which means your requests will start with /api
to reach the listUploadedFiles method you need to hit localhost:8080/api/

Categories