Web App not serving static resources using Spring Boot and Tomcat - java

Hello I am having troubles 'serving' resources with my web server, while some of my other resources are 'serving.' (graphs.js is loading)
In my browser console:
GET http://localhost:8080/js/app.js [HTTP/1.1 400 Bad Request 2ms]
GET http://localhost:8080/includes/header.html [HTTP/1.1 400 Bad Request 4ms]
GET http://localhost:8080/cs/bootstrap.min.css [HTTP/1.1 400 Bad Request 3ms]
But these files are located in my directory as such:
css/
bootstrap.min.css
includes/
header.html
js/
app.js
controllers/
graphs.js
When my server starts:
2014-07-28 08:25:06.748 INFO 5260 --- [ main] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: 8080
2014-07-28 08:25:06.939 INFO 5260 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2014-07-28 08:25:06.940 INFO 5260 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/7.0.52
2014-07-28 08:25:07.017 INFO 5260 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2014-07-28 08:25:07.017 INFO 5260 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1146 ms
2014-07-28 08:25:07.346 INFO 5260 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
**mapping**
2014-07-28 08:25:07.903 INFO 5260 --- [ main] o.s.w.s.c.a.WebMvcConfigurerAdapter : Adding welcome page: jndi:/localhost/index.html
2014-07-28 08:25:07.905 INFO 5260 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Root mapping to handler of type [class org.springframework.web.servlet.mvc.ParameterizableViewController]
2014-07-28 08:25:07.912 INFO 5260 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2014-07-28 08:25:07.912 INFO 5260 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2014-07-28 08:25:08.023 INFO 5260 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2014-07-28 08:25:08.147 INFO 5260 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080/http
2014-07-28 08:25:08.149 INFO 5260 --- [ main] c.c.i.qualifier.datacentral.Application : Started Application in 2.556 seconds (JVM running for 2.783)
and my HTML is like:
<script type="text/javascript" src="js/app.js"></script>
<script type="text/javascript" src="js/controllers/graphs.js"></script>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">

You have not stated if you have followed instructions for packaging as a war instead of a JAR and bundling Tomcat in. This does change things a little. Either way, take a look at the documentation here: http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-spring-mvc-static-content
Bascally, out of the box, you can place static content in one of the locations mentioned: /static, /public, /resources or /META-INF/resorces. As for the location of these folders, well either at the root of the servlet context or on the classpath.
You can find a very basic Tomcat application here: https://github.com/mmeany/spring-boot-web-mvc that does the job.

Related

Can Spring logging into multiple files by groups?

According to This post, I can log my application log to multiple files manually. Can I do it by the group listed in Spring docs.?
Example below:
Tomcat.log
2022-05-09 17:13:37.738 INFO 40656 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-05-09 17:13:37.746 INFO 40656 --- [ main] com.example.MyApplication : Started MyApplication in 7.302 seconds (JVM running for 8.053)
2022-05-09 17:16:03.503 INFO 40656 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-05-09 17:16:03.504 INFO 40656 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-05-09 17:16:03.506 INFO 40656 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms
Hibernate.log
Hibernate:
SELECT * FROM USER_MASTER;
Hibernate:
SELECT * FROM USER_CONFIG;

Failed to validate data received from Authorization service - could not validate state

I downloaded ms-identity-java-webapp archive and updated the application.properties file with the Azure AD details.
When I started the Spring Boot application, I got a login page. After clicking login button, I got a microsoft login page and after logging in with the user account, I got the following log lines with an error page:
2020-09-23 16:53:06.982 INFO 708 --- [ main] c.m.a.m.MsalWebSampleApplication : Starting MsalWebSampleApplication with PID 708 (C:\Users\testuser\Downloads\ms-identity-java-webapp-master\msal-java-webapp-sample\target\classes started by testuser in C:\Users\testuser\Downloads\ms-identity-java-webapp-master\msal-java-webapp-sample)
2020-09-23 16:53:06.985 INFO 708 --- [ main] c.m.a.m.MsalWebSampleApplication : No active profile set, falling back to default profiles: default
2020-09-23 16:53:08.466 INFO 708 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-09-23 16:53:08.497 INFO 708 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-09-23 16:53:08.497 INFO 708 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.17]
2020-09-23 16:53:08.646 INFO 708 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-09-23 16:53:08.647 INFO 708 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1613 ms
2020-09-23 16:53:08.967 INFO 708 --- [ main] .s.s.UserDetailsServiceAutoConfiguration :
Using generated security password: 970ff480-0c7d-4cd0-b657-000c23a68ab4
2020-09-23 16:53:09.148 INFO 708 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#6813a331, org.springframework.security.web.context.SecurityContextPersistenceFilter#27494e46, org.springframework.security.web.header.HeaderWriterFilter#68105edc, org.springframework.security.web.csrf.CsrfFilter#6e4ea0bd, org.springframework.security.web.authentication.logout.LogoutFilter#3e598df9, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#1e411d81, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#75504cef, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#1bd81830, org.springframework.security.web.session.SessionManagementFilter#470a9030, org.springframework.security.web.access.ExceptionTranslationFilter#28782602]
2020-09-23 16:53:09.373 INFO 708 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-09-23 16:53:09.561 INFO 708 --- [ main] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page template: index
2020-09-23 16:53:09.710 INFO 708 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-09-23 16:53:09.715 INFO 708 --- [ main] c.m.a.m.MsalWebSampleApplication : Started MsalWebSampleApplication in 3.211 seconds (JVM running for 4.717)
2020-09-23 16:53:29.556 INFO 708 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-09-23 16:53:29.556 INFO 708 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2020-09-23 16:53:29.562 INFO 708 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 6 ms
Failed to validate data received from Authorization service - could not validate state
Has anyone faced this issue? How can I resolve this?
This issue was already addressed on GitHub and was already fixed. Please go through the solution given here .

Launching two spring boot apps at the same time using maven

I have two spring boot apps with their own application.properties.
One is in my src/main/resources as application.properties and the other as test.properties in src/test/resources.
I want it so that when I launch my spring boot app in main, it also simultaneously launches the spring boot app in my test. I want to do this in Maven command line but I was also wondering if it is possible to do in Spring Boot as well, perhaps programmatically?
The spring boot apps are running on localhost but two different ports.
The one in main is running on localhost:28433 and the other on localhost:9119.
I have tried running this mvn command:
mvn spring-boot:run -Drun.arguments="--server.port=9119""--server.port=28433"
I am not sure this works though.. when I run it in my terminal it outputs this:
t.TomcatWebServer : Tomcat initialized with port(s): 28433 (http)
2019-08-12 15:25:51.641 INFO 37469 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-08-12 15:25:51.641 INFO 37469 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/9.0.12
2019-08-12 15:25:51.649 INFO 37469 --- [ main] 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/asluborski/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]
2019-08-12 15:25:51.707 INFO 37469 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-08-12 15:25:51.707 INFO 37469 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 934 ms
2019-08-12 15:25:51.731 INFO 37469 --- [ main] o.s.b.w.servlet.ServletRegistrationBean : Servlet messageDispatcherServlet mapped to [/nulogix/ws/*]
2019-08-12 15:25:51.732 INFO 37469 --- [ main] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2019-08-12 15:25:51.735 INFO 37469 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-08-12 15:25:51.735 INFO 37469 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-08-12 15:25:51.735 INFO 37469 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'formContentFilter' to: [/*]
2019-08-12 15:25:51.736 INFO 37469 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2019-08-12 15:25:51.760 DEBUG 37469 --- [ main] c.n.b.service.PredictionEngineService : billing.engine.address=127.0.0.1
2019-08-12 15:25:51.760 DEBUG 37469 --- [ main] c.n.b.service.PredictionEngineService : billing.engine.port=9119
2019-08-12 15:25:51.760 DEBUG 37469 --- [ main] c.n.b.service.PredictionEngineService : Using http://127.0.0.1:9119
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.sun.xml.bind.v2.runtime.reflect.opt.Injector (file:/Users/asluborski/.m2/repository/com/sun/xml/bind/jaxb-impl/2.2.11/jaxb-impl-2.2.11.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
WARNING: Please consider reporting this to the maintainers of com.sun.xml.bind.v2.runtime.reflect.opt.Injector
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
2019-08-12 15:25:52.037 DEBUG 37469 --- [ main] c.n.billing.ws.endpoint.AnalyzeEndPoint : billing.engine.api.version=0.97
2019-08-12 15:25:52.038 DEBUG 37469 --- [ main] c.n.billing.ws.endpoint.AnalyzeEndPoint : billing.engine.core.version=0.97
2019-08-12 15:25:52.038 DEBUG 37469 --- [ main] c.n.billing.ws.endpoint.AnalyzeEndPoint : billing.engine.core.name=Nulogix_Patient_Responsibility
2019-08-12 15:25:52.039 DEBUG 37469 --- [ main] c.n.b.ws.endpoint.GetVersionEndPoint : billing.engine.api.version=0.97
2019-08-12 15:25:52.184 INFO 37469 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-08-12 15:25:52.398 INFO 37469 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 28433 (http) with context path ''
2019-08-12 15:25:52.402 INFO 37469 --- [ main] com..billing.App : Started App in 1.995 seconds (JVM running for 9.911)
It says above that it is using 127.0.0.1:9119 but it seems to only start my main App but not my test App which is specifically called mockServerApp so I do not think it is doing what I want...
How do I launch these simultaneously?
I'm can't tell what mockServerApp is being used for, but I don't think bootRun handles multiple applications or even scans your test classes.
If you want to mock an external dependency for unit testing purposes, you should wrap the calls in a proxy class of some sort and use #MockBean to inject a mock instance.
If you want to deploy a stub external dependency for development purposes, you could create a separate project for the stub as a parent directory that would invoke maven on startup. You could even implement the mock in a different framework or language.
The most straightforward option, though would be to write a shell script that launches and kills both services.
For specifying the ports, in the application.properties of each set the server.port to be an environment variable:
primary application.conf:
server.port=${MY_APP_PORT:28433}
mock application.conf:
server.port=${MOCK_APP_PORT:9119}
For launching external dependencies in integration tests, check out Testcontainers

Spring Boot Controller not registered, gets 404 - package structure OK

I'm so frustrated with this one... Controller is not being registered by Spring Boot (at least I don't see it in logs).
The controller class is located in the package UNDER package of main app class... Which is the most common issue that people came across.
In my case, I'm using Maven and following dependencies (giving you only the crucial ones):
spring-boot-starter-data-jpa
spring-boot-starter-web
spring-boot-starter-validation
spring-boot-configuration-processor
I'm also using some dependencies for Hibernate.
In the log, I can see only things related to Hibernate - you can see it here.
When I'm hitting one of the controller's URLs, I'm getting this in Postman:
{
"timestamp": 1515870369837,
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/hello"
}
Then, additional log comes up:
sty 13, 2018 8:06:01 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'dispatcherServlet'
But nothing else really happens... I completely don't get it, it's the first time I've got an issue with sth such trivial like controller... And really couldn't find a solution on this one on StackOverflow.
Here's the code of the controllers I'm using:
#RestController("/parkingPlaces")
public class ParkingPlacesController {
#Resource
ParkingPlaceService ppService;
#RequestMapping("/find")
List<ParkingPlaceDTO> findParkingPlaces(#RequestBody GpsDTO position) {
return ppService.findParkingPlaces(position.getLat(), position.getLon());
}
#RequestMapping("/find/ray")
List<ParkingPlaceDTO> findParkingPlacesWithinRadius(#RequestBody GpsDTO position) {
return ppService.findParkingPlaces(position.getLat(), position.getLon(), position.getRay());
}
}
The other one is even simpler:
#Controller
public class TestController {
#RequestMapping("/hello")
public String hello() {
return "Hello!";
}
}
Please help guys :(
UPDATE #1
I've noticed that there was some mess with logging dependencies... Only Hibernate-related things were logged, which made me think it was OK, but I've done some clean-up and logs are evident now. I can see that controllers paths are being registered...
2018-01-14 20:34:57.602 INFO 8572 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-01-14 20:34:59.253 INFO 8572 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#3290cd1d: startup date [Sun Jan 14 20:34:46 CET 2018]; root of context hierarchy
2018-01-14 20:34:59.506 INFO 8572 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/find]}" onto java.util.List<pl.ppclone.dto.ParkingPlaceDTO> pl.ppclone.controller.ParkingPlacesController.findParkingPlaces(pl.ppclone.dto.GpsDTO)
2018-01-14 20:34:59.508 INFO 8572 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/find/ray]}" onto java.util.List<pl.ppclone.dto.ParkingPlaceDTO> pl.ppclone.controller.ParkingPlacesController.findParkingPlacesWithinRadius(pl.ppclone.dto.GpsDTO)
2018-01-14 20:34:59.513 INFO 8572 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/hello],methods=[GET]}" onto public java.lang.String pl.ppclone.controller.TestController.hello()
2018-01-14 20:34:59.524 INFO 8572 --- [ 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)
2018-01-14 20:34:59.527 INFO 8572 --- [ 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)
2018-01-14 20:34:59.607 INFO 8572 --- [ restartedMain] o.s.w.s.h.BeanNameUrlHandlerMapping : Mapped URL path [/parkingPlaces] onto handler '/parkingPlaces'
2018-01-14 20:34:59.654 INFO 8572 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-01-14 20:34:59.654 INFO 8572 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-01-14 20:34:59.826 INFO 8572 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-01-14 20:35:00.528 INFO 8572 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2018-01-14 20:35:00.730 INFO 8572 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-01-14 20:35:00.868 INFO 8572 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
I managed to found the solution. With the help of debugger I've noticed that /hello was indeed called... As it was only a test controller, I've started to playing with the real problem, which was RestController. Then I've noticed that this #RestController("mainPath") actually doesn't work as I intended (which was providing additional path before each methods path). So the solution was to write
#RestController
#RequestMapping("mainPath")
And so it works as intended :)
You haven't specified http method
you either should go
#RequestMapping(value = "/hello", method = RequestMethod.GET)
or
#GetMapping("/hello")

Camel - Can't access rest service

I'm running camel via spring and camel boot with embedded tomcat.
I have a simple camel route that is configuring correctly and consuming that I can see in the logs, but when i try to access it, it is giving 404 with localhost:8080/hi.
My Route
#Component
public class ServiceRoute extends RouteBuilder {
#Autowired
private SampleBean sampleBean;
#Override
public void configure() throws Exception {
from("rest:get:hi").to("bean:sampleBean");
}
}
My Main class
#Configuration
#SpringBootApplication
#ComponentScan(basePackages = { "routes", "service" },
excludeFilters = {#ComponentScan.Filter(value = Controller.class,
type = FilterType.ANNOTATION)})
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Gradle dependencies
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile 'org.apache.camel:camel-spring-boot-starter:2.17.0'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-
web', version: '1.4.2.RELEASE'
compile group: 'org.apache.camel', name: 'camel-servlet', version:
'2.18.1'
}
Logs
2016-12-12 12:37:39.860 INFO 24684 --- [ main] root.Application : Starting Application on ram.tscpt.local with PID 24684 (/Users/srikanth/emulya/build/classes/main started by srikanth in /Users/srikanth/emulya)
2016-12-12 12:37:39.865 INFO 24684 --- [ main] root.Application : No active profile set, falling back to default profiles: default
2016-12-12 12:37:39.979 INFO 24684 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#4facf68f: startup date [Mon Dec 12 12:37:39 SAST 2016]; root of context hierarchy
2016-12-12 12:37:41.866 INFO 24684 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.apache.camel.spring.boot.CamelAutoConfiguration' of type [class org.apache.camel.spring.boot.CamelAutoConfiguration$$EnhancerBySpringCGLIB$$a11fb1e5] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-12-12 12:37:42.597 INFO 24684 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-12-12 12:37:42.617 INFO 24684 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2016-12-12 12:37:42.618 INFO 24684 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.5
2016-12-12 12:37:42.756 INFO 24684 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2016-12-12 12:37:42.756 INFO 24684 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2782 ms
2016-12-12 12:37:42.959 INFO 24684 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2016-12-12 12:37:42.983 INFO 24684 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-12-12 12:37:42.984 INFO 24684 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-12-12 12:37:42.985 INFO 24684 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-12-12 12:37:42.985 INFO 24684 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2016-12-12 12:37:43.525 INFO 24684 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#4facf68f: startup date [Mon Dec 12 12:37:39 SAST 2016]; root of context hierarchy
2016-12-12 12:37:43.651 INFO 24684 --- [ 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)
2016-12-12 12:37:43.653 INFO 24684 --- [ 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)
2016-12-12 12:37:43.703 INFO 24684 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-12-12 12:37:43.707 INFO 24684 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-12-12 12:37:43.778 INFO 24684 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-12-12 12:37:44.557 INFO 24684 --- [ main] o.a.c.i.converter.DefaultTypeConverter : Loaded 196 type converters
2016-12-12 12:37:44.890 INFO 24684 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-12-12 12:37:44.970 INFO 24684 --- [ main] o.a.camel.spring.boot.RoutesCollector : Loading additional Camel XML routes from: classpath:camel/*.xml
2016-12-12 12:37:44.973 INFO 24684 --- [ main] o.a.camel.spring.boot.RoutesCollector : Loading additional Camel XML rests from: classpath:camel-rest/*.xml
2016-12-12 12:37:44.974 INFO 24684 --- [ main] o.a.camel.spring.SpringCamelContext : Apache Camel 2.18.1 (CamelContext: camel-1) is starting
2016-12-12 12:37:44.976 INFO 24684 --- [ main] o.a.c.m.ManagedManagementStrategy : JMX is enabled
2016-12-12 12:37:45.548 INFO 24684 --- [ main] o.a.c.i.DefaultRuntimeEndpointRegistry : Runtime endpoint registry is in extended mode gathering usage statistics of all incoming and outgoing endpoints (cache limit: 1000)
2016-12-12 12:37:45.871 INFO 24684 --- [ main] o.a.camel.spring.SpringCamelContext : StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
2016-12-12 12:37:46.023 INFO 24684 --- [ main] o.a.camel.spring.SpringCamelContext : Route: route1 started and consuming from: servlet:/hi?httpMethodRestrict=GET
2016-12-12 12:37:46.024 INFO 24684 --- [ main] o.a.camel.spring.SpringCamelContext : Total 1 routes, of which 1 are started.
2016-12-12 12:37:46.026 INFO 24684 --- [ main] o.a.camel.spring.SpringCamelContext : Apache Camel 2.18.1 (CamelContext: camel-1) started in 1.050 seconds
2016-12-12 12:37:46.147 INFO 24684 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-12-12 12:37:46.157 INFO 24684 --- [ main] root.Application : Started Application in 6.985 seconds (JVM running for 7.475)
It's not working, because the Camel HTTP Servlet is not registered. CamelAutoConfiguration just starts the camel context.
You need to register the servlet yourself. The default name of the camel servlet is CamelServlet. Change your Application class:
#SpringBootApplication
#ComponentScan(basePackages = { "routes", "service" },
excludeFilters = {#ComponentScan.Filter(value = Controller.class,
type = FilterType.ANNOTATION)})
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
#Bean
public ServletRegistrationBean servletRegistrationBean() {
ServletRegistrationBean registration = new ServletRegistrationBean(new CamelHttpTransportServlet(), "/service/*");
registration.setName("CamelServlet");
return registration;
}
}
And then try to access http://localhost/service/hi
Btw, you don't need to add #Configuration to the class annotated with #SpringBootApplication.

Categories