I want to configure the spring-boot Actuator end points for our application. Below is my pom.xml file with spring-boot actuator dependency added.
When I start the application I don't see any of the /application/ URL endpoints registered as the documentation suggests. The documentation suggests that after adding the actuator dependency to the pom.xml that I should see extra mappings in the startup log, which I don't. What could be there problem here?
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>SpreadSheetUploadWeb</groupId>
<artifactId>SpreadSheetUploadWeb</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
<spring.version>5.0.8.RELEASE</spring.version>
<spring.boot.version>2.0.4.RELEASE</spring.boot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.boot.version}</version>
<scope>test</scope>
</dependency>
<!-- Actuator for application Health/State monitoring -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-browser</artifactId>
</dependency>
Here is a startup log:
2018-08-08 14:16:40 INFO o.f.core.internal.command.DbMigrate - Schema "DB2INST " is up to date. No migration necessary.
2018-08-08 14:16:41 INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/bluecost/costspreadsheet/{uploader}],methods=[GET]}" onto public org.springframework.http.ResponseEntity<java.util.List<com.ibm.cio.cloud.cost.spreadsheet.domain.CostSpreadsheet>> com.ibm.cio.cloud.cost.spreadsheet.rest.controller.BlueCostRestController.getCostSpreadsheetByUploader(java.lang.String)
2018-08-08 14:16:41 INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/bluecost/costspreadsheet/{uploader}],methods=[GET]}" onto public org.springframework.http.ResponseEntity<java.util.List<com.ibm.cio.cloud.cost.spreadsheet.domain.CostSpreadsheet>> com.ibm.cio.cloud.cost.spreadsheet.rest.controller.BlueCostRestController.getCostSpreadsheetByUploader(java.lang.String)
2018-08-08 14:16:41 INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/bluecost/sscdata/],methods=[GET]}" onto public org.springframework.http.ResponseEntity<java.util.List<com.ibm.cio.cloud.cost.spreadsheet.domain.BluecostSSCData>> com.ibm.cio.cloud.cost.spreadsheet.rest.controller.BlueCostRestController.getAllBluecostSSCData()
2018-08-08 14:16:41 INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/bluecost/sscdata/],methods=[GET]}" onto public org.springframework.http.ResponseEntity<java.util.List<com.ibm.cio.cloud.cost.spreadsheet.domain.BluecostSSCData>> com.ibm.cio.cloud.cost.spreadsheet.rest.controller.BlueCostRestController.getAllBluecostSSCData()
2018-08-08 14:16:41 INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/bluecost/sscdata/],methods=[POST]}" onto public org.springframework.http.ResponseEntity<?> com.ibm.cio.cloud.cost.spreadsheet.rest.controller.BlueCostRestController.createBluecostSSCData(com.ibm.cio.cloud.cost.spreadsheet.domain.BluecostSSCData)
2018-08-08 14:16:41 INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/bluecost/sscdata/],methods=[POST]}" onto public org.springframework.http.ResponseEntity<?> com.ibm.cio.cloud.cost.spreadsheet.rest.controller.BlueCostRestController.createBluecostSSCData(com.ibm.cio.cloud.cost.spreadsheet.domain.BluecostSSCData)
2018-08-08 14:16:41 INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/bluecost/spreadsheet/upload],methods=[POST]}" onto public org.springframework.http.ResponseEntity<?> com.ibm.cio.cloud.cost.spreadsheet.rest.controller.BlueCostRestController.uploadSpreadsheet(org.springframework.web.multipart.MultipartFile)
2018-08-08 14:16:41 INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/bluecost/spreadsheet/upload],methods=[POST]}" onto public org.springframework.http.ResponseEntity<?> com.ibm.cio.cloud.cost.spreadsheet.rest.controller.BlueCostRestController.uploadSpreadsheet(org.springframework.web.multipart.MultipartFile)
2018-08-08 14:16:41 INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/bluecost/spreadsheet/{uploader}/{filename}],methods=[DELETE]}" onto public org.springframework.http.ResponseEntity<?> com.ibm.cio.cloud.cost.spreadsheet.rest.controller.BlueCostRestController.deleteUploadedSpreadsheet(java.lang.String,java.lang.String)
2018-08-08 14:16:41 INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/bluecost/spreadsheet/{uploader}/{filename}],methods=[DELETE]}" onto public org.springframework.http.ResponseEntity<?> com.ibm.cio.cloud.cost.spreadsheet.rest.controller.BlueCostRestController.deleteUploadedSpreadsheet(java.lang.String,java.lang.String)
2018-08-08 14:16:41 INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/bluecost/sscdata/{uploader}],methods=[GET]}" onto public org.springframework.http.ResponseEntity<?> com.ibm.cio.cloud.cost.spreadsheet.rest.controller.BlueCostRestController.findSSCDataByUploader(java.lang.String)
2018-08-08 14:16:41 INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/bluecost/sscdata/{uploader}],methods=[GET]}" onto public org.springframework.http.ResponseEntity<?> com.ibm.cio.cloud.cost.spreadsheet.rest.controller.BlueCostRestController.findSSCDataByUploader(java.lang.String)
2018-08-08 14:16:41 INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/swagger-resources/configuration/ui]}" onto public org.springframework.http.ResponseEntity<springfox.documentation.swagger.web.UiConfiguration> springfox.documentation.swagger.web.ApiResourceController.uiConfiguration()
2018-08-08 14:16:41 INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/swagger-resources/configuration/ui]}" onto public org.springframework.http.ResponseEntity<springfox.documentation.swagger.web.UiConfiguration> springfox.documentation.swagger.web.ApiResourceController.uiConfiguration()
2018-08-08 14:16:41 INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/swagger-resources]}" onto public org.springframework.http.ResponseEntity<java.util.List<springfox.documentation.swagger.web.SwaggerResource>> springfox.documentation.swagger.web.ApiResourceController.swaggerResources()
2018-08-08 14:16:41 INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/swagger-resources]}" onto public org.springframework.http.ResponseEntity<java.util.List<springfox.documentation.swagger.web.SwaggerResource>> springfox.documentation.swagger.web.ApiResourceController.swaggerResources()
2018-08-08 14:16:41 INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/swagger-resources/configuration/security]}" onto public org.springframework.http.ResponseEntity<springfox.documentation.swagger.web.SecurityConfiguration> springfox.documentation.swagger.web.ApiResourceController.securityConfiguration()
2018-08-08 14:16:41 INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/swagger-resources/configuration/security]}" onto public org.springframework.http.ResponseEntity<springfox.documentation.swagger.web.SecurityConfiguration> springfox.documentation.swagger.web.ApiResourceController.securityConfiguration()
2018-08-08 14:16:41 INFO o.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-08-08 14:16:41 INFO o.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-08-08 14:16:41 INFO o.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-08-08 14:16:41 INFO o.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-08-08 14:16:42 INFO s.d.s.w.PropertySourcedRequestMappingHandlerMapping - Mapped URL path [/v2/api-docs] onto method [public org.springframework.http.ResponseEntity<springfox.documentation.spring.web.json.Json> springfox.documentation.swagger2.web.Swagger2Controller.getDocumentation(java.lang.String,javax.servlet.http.HttpServletRequest)]
2018-08-08 14:16:42 INFO s.d.s.w.PropertySourcedRequestMappingHandlerMapping - Mapped URL path [/v2/api-docs] onto method [public org.springframework.http.ResponseEntity<springfox.documentation.spring.web.json.Json> springfox.documentation.swagger2.web.Swagger2Controller.getDocumentation(java.lang.String,javax.servlet.http.HttpServletRequest)]
2018-08-08 14:16:42 INFO o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-08 14:16:42 INFO o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-08 14:16:42 INFO o.s.w.s.m.m.a.RequestMappingHandlerAdapter - Looking for #ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#3967e60c: startup date [Wed Aug 08 14:16:34 MDT 2018]; root of context hierarchy
2018-08-08 14:16:42 INFO o.s.w.s.m.m.a.RequestMappingHandlerAdapter - Looking for #ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#3967e60c: startup date [Wed Aug 08 14:16:34 MDT 2018]; root of context hierarchy
2018-08-08 14:16:42 INFO o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-08 14:16:42 INFO o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-08 14:16:42 INFO o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-08 14:16:42 INFO o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-08 14:16:43 INFO o.s.j.e.a.AnnotationMBeanExporter - Registering beans for JMX exposure on startup
2018-08-08 14:16:43 INFO o.s.j.e.a.AnnotationMBeanExporter - Bean with name 'dataSource' has been autodetected for JMX exposure
2018-08-08 14:16:43 INFO o.s.j.e.a.AnnotationMBeanExporter - Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2018-08-08 14:16:43 INFO o.s.c.s.DefaultLifecycleProcessor - Starting beans in phase 2147483647
2018-08-08 14:16:43 INFO s.d.s.w.p.DocumentationPluginsBootstrapper - Context refreshed
2018-08-08 14:16:43 INFO s.d.s.w.p.DocumentationPluginsBootstrapper - Context refreshed
2018-08-08 14:16:43 INFO s.d.s.w.p.DocumentationPluginsBootstrapper - Found 1 custom documentation plugin(s)
2018-08-08 14:16:43 INFO s.d.s.w.p.DocumentationPluginsBootstrapper - Found 1 custom documentation plugin(s)
2018-08-08 14:16:43 INFO s.d.s.w.s.ApiListingReferenceScanner - Scanning for api listing references
2018-08-08 14:16:43 INFO s.d.s.w.s.ApiListingReferenceScanner - Scanning for api listing references
2018-08-08 14:16:43 INFO o.a.coyote.http11.Http11NioProtocol - Starting ProtocolHandler ["http-nio-8080"]
2018-08-08 14:16:43 INFO o.a.tomcat.util.net.NioSelectorPool - Using a shared selector for servlet write/read
2018-08-08 14:16:44 INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port(s): 8080 (http) with context path ''
2018-08-08 14:16:44 INFO c.i.c.c.c.s.BlueCostSpreadsheetUploadWebApplication - Started BlueCostSpreadsheetUploadWebApplication in 10.194 seconds (JVM running for 11.014)
It's working as expected, but the URLs that I've been trying to reach these through were not correct. I found the real URLs in the spring documentation, and for me they are:
http://localhost:8080/actuator
and
http://localhost:8080/browser.html
I am new to Spring's ecosystem. And I am stuck with this particular situation. My application server responds with 404 for all of my API endpoints.
This is my controller
package com.example.controllers;
import com.example.models.Movie;
import com.example.services.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
#RestController
public class MovieController {
#Autowired
private MovieService movieService;
#RequestMapping(value = "/movies", method = RequestMethod.GET)
#ResponseBody
public List<Movie> getAllMovies(){
return movieService.getAllMovies();
}
#RequestMapping(value = "/movies", method = RequestMethod.POST)
#ResponseBody
public Movie addNewMovie(#RequestBody Movie movie){
System.out.println("Hello World");
return movieService.addMovie(movie);
}
#RequestMapping(value = "/movies/{id}", method = RequestMethod.GET)
#ResponseBody
public Optional<Movie> getMovieById(#PathVariable String id){
return movieService.getMovieById(id);
}
#RequestMapping(value = "/movies", method = RequestMethod.PUT)
#ResponseBody
public Movie updateMovie(#RequestBody Movie movie){
return movieService.updateMovie(movie);
}
#RequestMapping(value = "/movies/{id}", method = RequestMethod.DELETE)
public void removeMovieById(#PathVariable String id){
movieService.deleteMovie(id);
}
}
And this my main class
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
#EnableAutoConfiguration
#ComponentScan
#SpringBootApplication
public class LearnSpringApplication{
public static void main(String[] args) {
SpringApplication.run(LearnSpringApplication.class, args);
}
}
I am running it on localhost and port is 8080. I did set up a small app prior to this one, and that worked as expected. However, I am guessing that it's because the controller is in a different package since in the previous app, the main class and the controller were in the same package.
Edit Here's my pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>learn_spring</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>learn_spring</name>
<description>Project to learn Spring</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>10</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
EDIT My Spring-Boot startup logs are
2018-05-03 17:16:44.937 INFO 14017 --- [ main] com.example.LearnSpringApplication : Starting LearnSpringApplication v0.0.1 on tfc with PID 14017 (/home/ayush/Workspace/learn_spring/target/learn_spring-0.0.1.jar started by ayush in /home/ayush/Workspace/learn_spring)
2018-05-03 17:16:44.940 INFO 14017 --- [ main] com.example.LearnSpringApplication : No active profile set, falling back to default profiles: default
2018-05-03 17:16:45.045 INFO 14017 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#6aba2b86: startup date [Thu May 03 17:16:45 IST 2018]; root of context hierarchy
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1 (jar:file:/home/ayush/Workspace/learn_spring/target/learn_spring-0.0.1.jar!/BOOT-INF/lib/spring-core-5.0.5.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-05-03 17:16:46.113 INFO 14017 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2018-05-03 17:16:46.138 INFO 14017 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-05-03 17:16:46.139 INFO 14017 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.29
2018-05-03 17:16:46.151 INFO 14017 --- [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: [/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib]
2018-05-03 17:16:46.218 INFO 14017 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-05-03 17:16:46.218 INFO 14017 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1186 ms
2018-05-03 17:16:46.336 INFO 14017 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2018-05-03 17:16:46.339 INFO 14017 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-05-03 17:16:46.340 INFO 14017 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-05-03 17:16:46.340 INFO 14017 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-05-03 17:16:46.340 INFO 14017 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-05-03 17:16:46.455 INFO 14017 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-05-03 17:16:46.720 INFO 14017 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#6aba2b86: startup date [Thu May 03 17:16:45 IST 2018]; root of context hierarchy
2018-05-03 17:16:46.786 INFO 14017 --- [ 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.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-05-03 17:16:46.787 INFO 14017 --- [ 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.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-05-03 17:16:46.817 INFO 14017 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-05-03 17:16:46.817 INFO 14017 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-05-03 17:16:47.060 INFO 14017 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2018-05-03 17:16:47.151 INFO 14017 --- [localhost:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:1, serverValue:12}] to localhost:27017
2018-05-03 17:16:47.155 INFO 14017 --- [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, 6, 3]}, minWireVersion=0, maxWireVersion=6, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=null, roundTripTimeNanos=2192957}
2018-05-03 17:16:47.323 INFO 14017 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-05-03 17:16:47.392 INFO 14017 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-05-03 17:16:47.395 INFO 14017 --- [ main] com.example.LearnSpringApplication : Started LearnSpringApplication in 2.89 seconds (JVM running for 3.296)
Sometimes is because of your package structure. Always make sure your controllers are in same package or sub-package level as the #SpringBootApplication class.
For example:
If application class is at com.a.b then controllers should be at com.a.b or com.a.b.c or com.a.b.c.d etc. You don't always have to add #ComponentScan to get them registered.
You're using IntelliJ IDEA community version, which does not support the Spring Framework:
see https://www.jetbrains.com/idea/features/editions_comparison_matrix.html for reference
Update
Since you're using the command line, then the above does not apply. I'll leave it here as a reference, though.
In the comments, you have specified that when running mvn clean package followed by java -jar target/whatever-your-project-name-is.jar, you get the following error:
Field movieService in com.example.controllers.MovieController required a bean of type 'com.example.services.MovieService' that could not be found.
Please make sure that:
you have a class MovieService in the package services
that class is annotated with the #Service annotation
Update 2
Since the above did not work, try replacing
#ComponentScan
by
#ComponentScan({"com.example.services", "com.example.controllers"})
in your LearnSpringApplication class.
Include all other packages that have classes annotated with #Component, #Service, #Controller, #RestController, or #Repository.
Note that this is a workaround. Normally, having #ComponentScan alone should be sufficient -- or as #DarrenForsythe mentionned in the comment, even just #SpringBootApplication should be sufficient for your case.
I had the same problem today and tried the simple solution provided above by #Daniel Moshi. It worked fine. Thanks.
Other option is using like below:
#SpringBootApplication(scanBasePackages = "com.example")
...with this the Controller can stay in any sub-package of com.example and works good even without explicit usage of #ComponentScan.
I have a spring boot/cloud micro-service application which is similar here. And have docker compose to start the service. Now this was running fast about two weeks back and the docker-compose up used to take me 2-3 minutes to start all the application.
But now it's taking me nearly 15 minutes to start the application. I am sure I haven't made any changes in docker configuration is last few weeks.
Any help is appreciable.
I am on Ubuntu 16.04
Docker version 17.09.1-ce, build 19e2cf6
docker-compose version 1.17.0, build ac53b73
Here's my docker-compose.yml
version: '2.1'
services:
config-service:
image: test/config-service
mem_limit: 1073741824
restart: unless-stopped
volumes:
- ~/logs/config-service:/app/logs
healthcheck:
test: ["CMD", "curl", "-I", "http://config-service:8888"]
interval: 5s
timeout: 3s
retries: 5
ports:
- 8888:8888
depends_on:
mongo-db:
condition: service_healthy
eureka-service:
image: test/eureka-service
mem_limit: 1073741824
restart: unless-stopped
volumes:
- ~/logs/eureka-service:/app/logs
healthcheck:
test: ["CMD", "curl", "-I", "http://eureka-service:8761"]
interval: 5s
timeout: 3s
retries: 5
ports:
- 8761:8761
depends_on:
config-service:
condition: service_healthy
user-service:
image: test/user-service
mem_limit: 1073741824
restart: unless-stopped
volumes:
- ~/logs/user-service:/app/logs
ports:
- 8080:8080
depends_on:
eureka-service:
condition: service_healthy
Tomcat log (trimmed as I reached max word limit)
2018-01-18 08:23:00,467 INFO [main] com.test.userservice.UserServiceApplication : The following profiles are active: docker
2018-01-18 08:23:00,636 INFO [main] org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#56aac163: startup date [Thu Jan 18 08:23:00 GMT 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#e2d56bf
2018-01-18 08:23:11,079 INFO [main] org.springframework.beans.factory.support.DefaultListableBeanFactory : Overriding bean definition for bean 'managementServletContext' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.actuate.autoconfigure.EndpointWebMvcHypermediaManagementContextConfiguration; factoryMethodName=managementServletContext; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/actuate/autoconfigure/EndpointWebMvcHypermediaManagementContextConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration; factoryMethodName=managementServletContext; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.class]]
2018-01-18 08:23:14,462 INFO [main] org.springframework.cloud.context.scope.GenericScope : BeanFactory id=ebfc4c4a-204e-3d20-ab06-5ee31c9ae744
2018-01-18 08:23:14,709 INFO [main] org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2018-01-18 08:23:16,511 INFO [main] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.sleuth.instrument.async.AsyncDefaultAutoConfiguration$DefaultAsyncConfigurerSupport' of type [org.springframework.cloud.sleuth.instrument.async.AsyncDefaultAutoConfiguration$DefaultAsyncConfigurerSupport$$EnhancerBySpringCGLIB$$bf6fe615] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-01-18 08:23:17,760 INFO [main] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.sleuth.annotation.SleuthAnnotationAutoConfiguration' of type [org.springframework.cloud.sleuth.annotation.SleuthAnnotationAutoConfiguration$$EnhancerBySpringCGLIB$$84938e84] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-01-18 08:23:20,662 INFO [main] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker : Bean 'sleuthAdvisorConfig' of type [org.springframework.cloud.sleuth.annotation.SleuthAdvisorConfig] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-01-18 08:23:20,909 INFO [main] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker : Bean 'security.oauth2.client-org.springframework.boot.autoconfigure.security.oauth2.OAuth2ClientProperties' of type [org.springframework.boot.autoconfigure.security.oauth2.OAuth2ClientProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-01-18 08:23:21,116 INFO [main] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration' of type [org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration$$EnhancerBySpringCGLIB$$39780452] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-01-18 08:23:21,561 INFO [main] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker : Bean 'resourceServerProperties' of type [org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-01-18 08:23:21,985 INFO [main] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.netflix.metrics.MetricsInterceptorConfiguration$MetricsRestTemplateConfiguration' of type [org.springframework.cloud.netflix.metrics.MetricsInterceptorConfiguration$MetricsRestTemplateConfiguration$$EnhancerBySpringCGLIB$$b45aee93] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-01-18 08:23:22,516 INFO [main] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$9e484b4f] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-01-18 08:23:23,191 INFO [main] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.sleuth.instrument.async.AsyncDefaultAutoConfiguration' of type [org.springframework.cloud.sleuth.instrument.async.AsyncDefaultAutoConfiguration$$EnhancerBySpringCGLIB$$6a11f471] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-01-18 08:23:23,576 INFO [main] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.sleuth.instrument.web.client.TraceWebClientAutoConfiguration$TraceOAuthConfiguration' of type [org.springframework.cloud.sleuth.instrument.web.client.TraceWebClientAutoConfiguration$TraceOAuthConfiguration$$EnhancerBySpringCGLIB$$c72adab1] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-01-18 08:23:30,323 INFO [main] org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2018-01-18 08:23:30,454 INFO [main] org.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-01-18 08:23:30,460 INFO [main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.23
2018-01-18 08:23:30,949 INFO [localhost-startStop-1] org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-01-18 08:23:30,971 INFO [localhost-startStop-1] org.springframework.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 30335 ms
2018-01-18 08:23:42,305 INFO [localhost-startStop-1] org.springframework.boot.web.servlet.FilterRegistrationBean : Mapping filter: 'metricsFilter' to: [/*]
2018-01-18 08:23:42,308 INFO [localhost-startStop-1] org.springframework.boot.web.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-01-18 08:23:42,308 INFO [localhost-startStop-1] org.springframework.boot.web.servlet.FilterRegistrationBean : Mapping filter: 'traceFilter' to: [/*]
2018-01-18 08:23:42,308 INFO [localhost-startStop-1] org.springframework.boot.web.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-01-18 08:23:42,308 INFO [localhost-startStop-1] org.springframework.boot.web.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-01-18 08:23:42,308 INFO [localhost-startStop-1] org.springframework.boot.web.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-01-18 08:23:42,310 INFO [localhost-startStop-1] org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2018-01-18 08:23:42,310 INFO [localhost-startStop-1] org.springframework.boot.web.servlet.FilterRegistrationBean : Mapping filter: 'webRequestLoggingFilter' to: [/*]
2018-01-18 08:23:42,310 INFO [localhost-startStop-1] org.springframework.boot.web.servlet.FilterRegistrationBean : Mapping filter: 'applicationContextIdFilter' to: [/*]
2018-01-18 08:23:42,310 INFO [localhost-startStop-1] org.springframework.boot.web.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2018-01-18 08:24:01,859 INFO [main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[mongo-db:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2018-01-18 08:24:01,875 INFO [main] org.mongodb.driver.cluster : Adding discovered server mongo-db:27017 to client view of cluster
2018-01-18 08:24:07,610 INFO [cluster-ClusterId{value='5a6059a0b3cb1f00072c45c2', description='null'}-mongo-db:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:1, serverValue:28}] to mongo-db:27017
2018-01-18 08:24:07,613 INFO [cluster-ClusterId{value='5a6059a0b3cb1f00072c45c2', description='null'}-mongo-db:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=mongo-db:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 4, 10]}, minWireVersion=0, maxWireVersion=5, maxDocumentSize=16777216, roundTripTimeNanos=577257}
2018-01-18 08:24:07,614 INFO [cluster-ClusterId{value='5a6059a0b3cb1f00072c45c2', description='null'}-mongo-db:27017] org.mongodb.driver.cluster : Discovered cluster type of STANDALONE
2018-01-18 08:28:53,270 WARN [main] com.netflix.config.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2018-01-18 08:28:54,188 INFO [main] com.netflix.config.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2018-01-18 08:28:56,203 WARN [main] com.netflix.config.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2018-01-18 08:28:56,204 INFO [main] com.netflix.config.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2018-01-18 08:29:37,452 INFO [main] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#56aac163: startup date [Thu Jan 18 08:23:00 GMT 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#e2d56bf
2018-01-18 08:29:39,074 INFO [main] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter : Detected ResponseBodyAdvice bean in org.springframework.boot.actuate.autoconfigure.EndpointWebMvcHypermediaManagementContextConfiguration$ActuatorEndpointLinksAdvice
2018-01-18 08:29:54,522 INFO [main] org.springframework.web.servlet.mvc.method.annotation.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-18 08:29:54,535 INFO [main] org.springframework.web.servlet.mvc.method.annotation.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-18 08:30:02,532 INFO [main] org.springframework.web.servlet.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-01-18 08:30:02,532 INFO [main] org.springframework.web.servlet.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-01-18 08:30:05,657 INFO [main] org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver : Detected #ExceptionHandler methods in exceptionHandler
2018-01-18 08:30:05,657 INFO [main] org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver : Detected ResponseBodyAdvice implementation in org.springframework.boot.actuate.autoconfigure.EndpointWebMvcHypermediaManagementContextConfiguration$ActuatorEndpointLinksAdvice
2018-01-18 08:30:26,080 INFO [main] org.springframework.web.servlet.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-01-18 08:33:58,388 INFO [main] org.springframework.security.web.DefaultSecurityFilterChain : Creating filter chain: org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration$LazyEndpointPathRequestMatcher#723ed581, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#6b760460, org.springframework.security.web.context.SecurityContextPersistenceFilter#7af1cd63, org.springframework.security.web.header.HeaderWriterFilter#667e34b1, org.springframework.web.filter.CorsFilter#796065aa, org.springframework.security.web.authentication.logout.LogoutFilter#62515a47, org.springframework.security.web.authentication.www.BasicAuthenticationFilter#6dc1484, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#3c2772d1, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#89c65d5, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#28a6301f, org.springframework.security.web.session.SessionManagementFilter#6dba847b, org.springframework.security.web.access.ExceptionTranslationFilter#45673f68, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#5a5c128]
2018-01-18 08:34:00,867 INFO [main] org.springframework.security.web.DefaultSecurityFilterChain : Creating filter chain: org.springframework.security.web.util.matcher.AnyRequestMatcher#1, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#766a4535, org.springframework.security.web.context.SecurityContextPersistenceFilter#7351a16e, org.springframework.security.web.header.HeaderWriterFilter#38eb2fb0, org.springframework.security.web.authentication.logout.LogoutFilter#4074023c, org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter#562457e1, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#5bb7643d, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#3ac04654, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#63718b93, org.springframework.security.web.session.SessionManagementFilter#4567e53d, org.springframework.security.web.access.ExceptionTranslationFilter#336365bc, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#3721177d]
2018-01-18 08:34:01,272 INFO [main] org.springframework.security.web.DefaultSecurityFilterChain : Creating filter chain: OrRequestMatcher [requestMatchers=[Ant [pattern='/**']]], [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#35835fa, org.springframework.security.web.context.SecurityContextPersistenceFilter#2df3c564, org.springframework.security.web.header.HeaderWriterFilter#aac3f4e, org.springframework.security.web.authentication.logout.LogoutFilter#518cf84a, org.springframework.security.web.authentication.www.BasicAuthenticationFilter#62e7dffa, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#2715644a, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#4c2869a9, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#56f71edb, org.springframework.security.web.session.SessionManagementFilter#1f38957, org.springframework.security.web.access.ExceptionTranslationFilter#7a2e0858, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#b8a7e43]
2018-01-18 08:34:43,897 INFO [main] org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler : Initializing ExecutorService
2018-01-18 08:34:52,517 INFO [main] org.springframework.jmx.export.annotation.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-01-18 08:34:53,014 INFO [main] org.springframework.jmx.export.annotation.AnnotationMBeanExporter : Bean with name 'environmentManager' has been autodetected for JMX exposure
2018-01-18 08:34:53,016 INFO [main] org.springframework.jmx.export.annotation.AnnotationMBeanExporter : Bean with name 'configurationPropertiesRebinder' has been autodetected for JMX exposure
2018-01-18 08:34:53,016 INFO [main] org.springframework.jmx.export.annotation.AnnotationMBeanExporter : Bean with name 'refreshEndpoint' has been autodetected for JMX exposure
2018-01-18 08:34:53,154 INFO [main] org.springframework.jmx.export.annotation.AnnotationMBeanExporter : Bean with name 'restartEndpoint' has been autodetected for JMX exposure
2018-01-18 08:34:53,155 INFO [main] org.springframework.jmx.export.annotation.AnnotationMBeanExporter : Bean with name 'serviceRegistryEndpoint' has been autodetected for JMX exposure
2018-01-18 08:34:53,165 INFO [main] org.springframework.jmx.export.annotation.AnnotationMBeanExporter : Bean with name 'refreshScope' has been autodetected for JMX exposure
2018-01-18 08:34:53,360 INFO [main] org.springframework.jmx.export.annotation.AnnotationMBeanExporter : Located managed bean 'environmentManager': registering with JMX server as MBean [org.springframework.cloud.context.environment:name=environmentManager,type=EnvironmentManager]
2018-01-18 08:34:54,090 INFO [main] org.springframework.jmx.export.annotation.AnnotationMBeanExporter : Located managed bean 'restartEndpoint': registering with JMX server as MBean [org.springframework.cloud.context.restart:name=restartEndpoint,type=RestartEndpoint]
2018-01-18 08:34:54,190 INFO [main] org.springframework.jmx.export.annotation.AnnotationMBeanExporter : Located managed bean 'serviceRegistryEndpoint': registering with JMX server as MBean [org.springframework.cloud.client.serviceregistry.endpoint:name=serviceRegistryEndpoint,type=ServiceRegistryEndpoint]
2018-01-18 08:34:54,325 INFO [main] org.springframework.jmx.export.annotation.AnnotationMBeanExporter : Located managed bean 'refreshScope': registering with JMX server as MBean [org.springframework.cloud.context.scope.refresh:name=refreshScope,type=RefreshScope]
2018-01-18 08:34:54,561 INFO [main] org.springframework.jmx.export.annotation.AnnotationMBeanExporter : Located managed bean 'configurationPropertiesRebinder': registering with JMX server as MBean [org.springframework.cloud.context.properties:name=configurationPropertiesRebinder,context=56aac163,type=ConfigurationPropertiesRebinder]
2018-01-18 08:34:54,699 INFO [main] org.springframework.jmx.export.annotation.AnnotationMBeanExporter : Located managed bean 'refreshEndpoint': registering with JMX server as MBean [org.springframework.cloud.endpoint:name=refreshEndpoint,type=RefreshEndpoint]
2018-01-18 08:34:58,144 INFO [main] org.springframework.context.support.DefaultLifecycleProcessor : Starting beans in phase 0
2018-01-18 08:34:58,540 INFO [main] org.springframework.cloud.netflix.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2018-01-18 08:35:01,069 INFO [main] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1
2018-01-18 08:35:12,136 INFO [main] com.netflix.discovery.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson
2018-01-18 08:35:12,137 INFO [main] com.netflix.discovery.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson
2018-01-18 08:35:13,882 INFO [main] com.netflix.discovery.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml
2018-01-18 08:35:13,882 INFO [main] com.netflix.discovery.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml
2018-01-18 08:35:16,570 INFO [main] com.netflix.discovery.shared.resolver.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
2018-01-18 08:35:17,044 INFO [main] com.netflix.discovery.DiscoveryClient : Disable delta property : false
2018-01-18 08:35:17,044 INFO [main] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null
2018-01-18 08:35:17,044 INFO [main] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false
2018-01-18 08:35:17,044 INFO [main] com.netflix.discovery.DiscoveryClient : Application is null : false
2018-01-18 08:35:17,045 INFO [main] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true
2018-01-18 08:35:17,045 INFO [main] com.netflix.discovery.DiscoveryClient : Application version is -1: true
2018-01-18 08:35:17,045 INFO [main] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
2018-01-18 08:35:19,108 INFO [main] com.netflix.discovery.DiscoveryClient : The response status is 200
2018-01-18 08:35:19,109 INFO [main] com.netflix.discovery.DiscoveryClient : Starting heartbeat executor: renew interval is: 30
2018-01-18 08:35:19,151 INFO [main] com.netflix.discovery.InstanceInfoReplicator : InstanceInfoReplicator onDemand update allowed rate per min is 4
2018-01-18 08:35:19,221 INFO [main] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1516264519221 with initial instances count: 2
2018-01-18 08:35:21,590 INFO [main] org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry : Registering application user-service with eureka with status UP
2018-01-18 08:35:21,592 INFO [main] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1516264521592, current=UP, previous=STARTING]
2018-01-18 08:35:21,597 INFO [DiscoveryClient-InstanceInfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_USER-SERVICE/fad9b0071a33:user-service:8080: registering service...
2018-01-18 08:35:22,235 INFO [DiscoveryClient-InstanceInfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_USER-SERVICE/fad9b0071a33:user-service:8080 - registration status: 204
2018-01-18 08:35:56,660 INFO [main] org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2018-01-18 08:35:56,669 INFO [main] org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration : Updating port to 8080
2018-01-18 08:35:56,747 INFO [main] com.test.userservice.UserServiceApplication : Started UserServiceApplication in 805.764 seconds (JVM running for 807.935)
I'm facing a problem on a large scale application using SpringBoot and AspectJ for logging purposes. The logging works fine for Spring Beans, but does not work for unmanaged classes (the ones I instantiate with 'new').
I've created a sample app where you can see the problem happening, you can access it here:
https://bitbucket.org/tomkro/stack_question
The application is pretty simple, the Gradle file is a common with the standard Spring Boot starters.
There are 5 relevant classes here.
Application.java, which is the main class:
#EnableAspectJAutoProxy
#EnableLoadTimeWeaving(aspectjWeaving= EnableLoadTimeWeaving.AspectJWeaving.ENABLED)
#SpringBootApplication(scanBasePackages = "com.test.*")
public class Application {
public static void main(final String[] args) {
SpringApplication.run(Application.class, args);
}
}
The AspectConfig file (which for the sake of simplicity also defines the RestController, could be easily separated files)
#RestController
#Configuration
#ComponentScan(basePackages = {"com.test"})
public class AspectConfig {
#Bean
public TestLogger testLogger(){
return new TestLogger();
}
#Autowired
TestClass testClass;
#RequestMapping("/")
public int get() {
return testClass.methodFromClass1();
}
}
The TestLogger, which defines the aspect for this app:
#Aspect
public class TestLogger {
public TestLogger() {
}
#Around("execution( * com.test.classes..*.*(..))")
public Object aroundExecution(ProceedingJoinPoint pjp) throws Throwable {
String packageName = pjp.getSignature().getDeclaringTypeName();
String methodName = pjp.getSignature().getName();
long start = System.currentTimeMillis();
System.out.println(packageName + "." + methodName + " - Starting execution ");
Object output = pjp.proceed();
Long elapsedTime = System.currentTimeMillis() - start;
System.out.println(packageName + "." + methodName + " - Ending execution ["+elapsedTime+" ms]");
return output;
}
}
And then there's two files, one managed by Spring, the other not:
TestClass1:
#Component
public class TestClass {
public int methodFromClass1() {
TestClass2 test = new TestClass2();
return test.methodFromClass2();
}
}
TestClass2
public class TestClass2 {
public int methodFromClass2() {
int a = 10;
int b = 5;
return b + a;
}
}
Also there's the aop.xml file in META-INF which specifies the Aspect
<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
<aspectj>
<weaver option="-debug">
<!-- only weave classes in our application-specific packages -->
<include within="com.test.*"/>
</weaver>
<aspects>
<!-- weave in just this aspect -->
<aspect name="com.test.utilities.TestLogger"/>
</aspects>
</aspectj>
I followed most of this build using the tutorial on the Spring documentation here , and I've been scratching my head for two days now and I can't figure out what's happening. The managed Bean logs fine, but the unmanaged one is not being logged.
I'm using the run.bat included in the project for starting, basically it does this:
call gradle build
java -javaagent:.\src\main\resources\aspectjweaver.jar -javaagent:.\src\main\resources\spring-instrument.jar -jar build\libs\Test-0.0.1-SNAPSHOT.jar
Both jars are the latest. Usually you only would need of the JAR's, but I saw someone using both and gave it a shot. This is the output after startup and execution of a call to "localhost:8080"
[LaunchedURLClassLoader#6d8a00e3] warning javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.3.0.RELEASE)
2016-04-08 15:21:44.116 INFO 20400 --- [ main] com.test.Application : Starting Application on PC000BR23205 with PID 20400 (C:\git\Test\build\libs\Test-0.0.1-SNAPSHOT.jar started by tkroth in C:\git\T
est)
2016-04-08 15:21:44.120 INFO 20400 --- [ main] com.test.Application : No profiles are active
2016-04-08 15:21:44.294 INFO 20400 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#2cd72cea: startup date [Fri Ap
r 08 15:21:44 BRT 2016]; root of context hierarchy
2016-04-08 15:21:44.950 INFO 20400 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'beanNameViewResolver' with a different definition: replacing [Root bean: class [null]; scope
=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; fa
ctoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]]
with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$W
ebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAut
oConfigurationAdapter.class]]
2016-04-08 15:21:45.872 INFO 20400 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-04-08 15:21:45.888 INFO 20400 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2016-04-08 15:21:45.891 INFO 20400 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.28
2016-04-08 15:21:45.987 INFO 20400 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2016-04-08 15:21:45.987 INFO 20400 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1695 ms
2016-04-08 15:21:46.342 INFO 20400 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2016-04-08 15:21:46.347 INFO 20400 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-04-08 15:21:46.348 INFO 20400 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-04-08 15:21:46.349 INFO 20400 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-04-08 15:21:46.349 INFO 20400 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2016-04-08 15:21:46.439 INFO 20400 --- [ main] o.s.c.w.DefaultContextLoadTimeWeaver : Found Spring's JVM agent for instrumentation
2016-04-08 15:21:46.455 INFO 20400 --- [ main] o.s.c.w.DefaultContextLoadTimeWeaver : Found Spring's JVM agent for instrumentation
[LaunchedURLClassLoader#6d8a00e3] warning javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified
2016-04-08 15:21:46.781 INFO 20400 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#2cd72cea:
startup date [Fri Apr 08 15:21:44 BRT 2016]; root of context hierarchy
2016-04-08 15:21:46.874 INFO 20400 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto public int com.test.configuration.AspectConfig.get()
2016-04-08 15:21:46.877 INFO 20400 --- [ 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.sp
ringframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2016-04-08 15:21:46.878 INFO 20400 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoco
nfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
2016-04-08 15:21:46.912 INFO 20400 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-04-08 15:21:46.912 INFO 20400 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-04-08 15:21:47.030 INFO 20400 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler
]
2016-04-08 15:21:47.133 INFO 20400 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-04-08 15:21:47.204 INFO 20400 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-04-08 15:21:47.210 INFO 20400 --- [ main] com.test.Application : Started Application in 3.481 seconds (JVM running for 4.306)
2016-04-08 15:21:51.680 INFO 20400 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2016-04-08 15:21:51.680 INFO 20400 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2016-04-08 15:21:51.704 INFO 20400 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 23 ms
com.test.classes.TestClass.methodFromClass1 - Starting execution
com.test.classes.TestClass.methodFromClass1 - Ending execution [15 ms]
As you can see, TestClass2 is never logged, although it's called. What am I missing here?
The real question is, how can I make non-beans to be handled by LTW in a SpringBoot environment? Feel free to commit changes on the repository I provided above.
I am getting below error when developing first web app in STS in Spring Boot (v1.2.3.RELEASE) while opening this url (http://localhost:8080/riyan/):
Error:
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri Jun 05 23:08:55 PKT 2015
There was an unexpected error (type=Not Found, status=404).
No message available
Application.properties
logging.config = ${app.root.dir}/config/logback.xml
spring.view.prefix = /WEB-INF/views/
spring.view.suffix = .jsp
spring.datasource.url=jdbc:hsqldb:file:${app.root.dir}/data/accounts;crypt_key=901a6105813eb65326bf35790a965432;crypt_type=blowfish;hsqldb.write_delay=false;create=false;sql.syntax_ora=true
spring.datasource.username=accounts
spring.datasource.password=accounts
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=none
spring.datasource-internal.jpa.database-platform=org.hibernate.dialect.HSQLDialect
HomeController.java
package com.riyan.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class HomeController {
#RequestMapping("/")
public String getHomePage() {
return "login";
}
}
JSP:
login.jsp is present at WEB-INF->views->login.jsp
Followings are contents from pivotal server console:
Console Output:
23:08:47.239 [localhost-startStop-1] INFO org.apache.tiles.access.TilesAccess - Publishing TilesContext for context: org.springframework.web.servlet.view.tiles3.SpringWildcardServletTilesApplicationContext
23:08:47.989 [localhost-startStop-1] INFO o.s.w.s.m.m.a.RequestMappingHandlerAdapter - Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#5596ab: startup date [Fri Jun 05 23:08:32 PKT 2015]; root of context hierarchy
23:08:48.333 [localhost-startStop-1] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" 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)
23:08:48.333 [localhost-startStop-1] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[text/html],custom=[]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
23:08:48.427 [localhost-startStop-1] INFO o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
23:08:48.427 [localhost-startStop-1] INFO o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
23:08:48.614 [localhost-startStop-1] INFO o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
Please let me know if anything further is required.
I don't see anything in your config that is setting the server context to "/riyan". You should add this to your application.properties
server.contextPath=/riyan
Otherwise you will probably find your actual login.jps is at
http://localhost:8080/