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/
Related
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.
In the official Spring tutorial code source coode there are no controller required, so I didn't put them in my sample, however when I try to run my simple app I keep getting for http://localhost:8080/ or for http://localhost:8080/invoice the error:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing
this as a fallback. Thu Mar 09 10:18:51 CET 2017 There was an
unexpected error (type=Not Found, status=404). No message available
Structure:
$ tree
.
├── domain
│ ├── Invoice.java
│ └── InvoiceRepository.java
├── QbsApplication.java
invoice.java:
package qbs.domain;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
#Entity
#Getter
#Setter
#ToString
public class Invoice {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String issuedBy;
protected Invoice() {
}
public Invoice(String issuedBy) {
this.issuedBy = issuedBy;
}
}
REPO:
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import java.util.List;
public interface InvoiceRepository extends PagingAndSortingRepository<Invoice, Long> {
List<Invoice> findByIssuedBy(#Param("issuer")String issuer);
}
and APP:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class QbsApplication {
public static void main(String[] args) {
SpringApplication.run(QbsApplication.class, args);
}
}
1. What seems to be the problem?
2. Can this be the lombok causing the issue (user the start.spring.io initializer though)?
EDIT
Spring BOot log:
2017-03-09 11:12:43.233 INFO 16837 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.0.12.Final}
2017-03-09 11:12:43.235 INFO 16837 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2017-03-09 11:12:43.236 INFO 16837 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2017-03-09 11:12:43.274 INFO 16837 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2017-03-09 11:12:43.370 INFO 16837 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2017-03-09 11:12:43.479 INFO 16837 --- [ main] o.h.e.j.e.i.LobCreatorBuilderImpl : HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
2017-03-09 11:12:43.481 INFO 16837 --- [ main] org.hibernate.type.BasicTypeRegistry : HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType#38ed139b
2017-03-09 11:12:43.695 WARN 16837 --- [ main] org.hibernate.orm.deprecation : HHH90000014: Found use of deprecated [org.hibernate.id.SequenceGenerator] sequence-based id generator; use org.hibernate.id.enhanced.SequenceStyleGenerator instead. See Hibernate Domain Model Mapping Guide for details.
2017-03-09 11:12:43.949 INFO 16837 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2017-03-09 11:12:44.464 INFO 16837 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#6385cb26: startup date [Thu Mar 09 11:12:40 CET 2017]; root of context hierarchy
2017-03-09 11:12:44.546 INFO 16837 --- [ 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-03-09 11:12:44.547 INFO 16837 --- [ 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-03-09 11:12:44.576 INFO 16837 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-03-09 11:12:44.576 INFO 16837 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-03-09 11:12:44.614 INFO 16837 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-03-09 11:12:44.923 INFO 16837 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-03-09 11:12:44.988 INFO 16837 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-03-09 11:12:44.994 INFO 16837 --- [ main] qbs.QbsApplication : Started QbsApplication in 4.875 seconds (JVM running for 5.356)
You forgot to annotate your repository with #RepositoryRestResource. If you don't, Spring will not auto generate the url mappings and it will just act as a normal repository. This is a feature of spring-data-rest. So, in your case:
#RepositoryRestResource(collectionResourceRel = "invoices", path = "invoices")
public interface InvoiceRepository extends PagingAndSortingRepository<Invoice, Long> {
List<Invoice> findByIssuedBy(#Param("issuer")String issuer);
}
Now curl http://localhost:8080/invoices will return all invoices.
Refer to the Spring Data Rest documentation for more info.
I am using Loggers in my Spring Web Application. But when I am enabling the logger at Debug/Info level, the logs inside the Spring Jars are also getting Printed in the Log file. Pls tell me how to stop internal Logs from getting displayed.
My Logger Implementation :
import org.apache.log4j.Logger;
static Logger log = Logger.getLogger(ClassName.class);
Log4j.properties
log4j.rootLogger=INFO, stdout, file
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File="location"
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
These are the Unwanted Logs and Many more like this ..
2015-03-05 20:16:02 INFO DispatcherServlet:444 - FrameworkServlet 'SpringApp': initialization started
2015-03-05 20:16:02 INFO XmlWebApplicationContext:495 - Refreshing WebApplicationContext for namespace 'SpringApp-servlet': startup date [Thu Mar 05 20:16:02 IST 2015]; root of context hierarchy
2015-03-05 20:16:02 INFO XmlBeanDefinitionReader:315 - Loading XML bean definitions from ServletContext resource [/WEB-INF/SpringApp-servlet.xml]
2015-03-05 20:16:02 INFO ClassPathBeanDefinitionScanner:202 - JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
2015-03-05 20:16:02 INFO ClassPathBeanDefinitionScanner:210 - JSR-330 'javax.inject.Named' annotation found and supported for component scanning
2015-03-05 20:16:02 INFO AutowiredAnnotationBeanPostProcessor:139 - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2015-03-05 20:16:02 INFO DefaultListableBeanFactory:557 - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#1a5e65f: defining beans [loadController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,org.springframework.web.servlet.view.InternalResourceViewResolver#0,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy
2015-03-05 20:16:02 INFO RequestMappingHandlerMapping:190 - Mapped "{[/logout],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.nagesh.testLoad.Controller.LoadController.logout(javax.servlet.http.HttpSession)
2015-03-05 20:16:02 INFO RequestMappingHandlerMapping:190 - Mapped "{[/login],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.nagesh.testLoad.Controller.LoadController.loginUI()
2015-03-05 20:16:02 INFO RequestMappingHandlerMapping:190 - Mapped "{[/loginAction],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.nagesh.testLoad.Controller.LoadController.loginClicked(java.lang.String,java.lang.String)
2015-03-05 20:16:02 INFO RequestMappingHandlerMapping:190 - Mapped "{[/loadLop],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.nagesh.testLoad.Controller.LoadController.loadLop()
2015-03-05 20:16:02 INFO RequestMappingHandlerMapping:190 - Mapped "{[/loadOthers],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.nagesh.testLoad.Controller.LoadController.loadOthers()
2015-03-05 20:16:02 INFO RequestMappingHandlerMapping:190 - Mapped "{[/jobStatus],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.nagesh.testLoad.Controller.LoadController.getJobStatus(javax.servlet.http.HttpSession)
2015-03-05 20:16:02 INFO RequestMappingHandlerMapping:190 - Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.nagesh.testLoad.Controller.LoadController.errorHandling()
2015-03-05 20:16:02 INFO RequestMappingHandlerMapping:190 - Mapped "{[/LOPAction],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.nagesh.testLoad.Controller.LoadController.LOPAction(java.lang.String,java.lang.String,java.lang.String,javax.servlet.http.HttpSession)
2015-03-05 20:16:02 INFO RequestMappingHandlerMapping:190 - Mapped "{[/PartsAction],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.nagesh.testLoad.Controller.LoadController.partsAction(java.lang.String,javax.servlet.http.HttpSession)
2015-03-05 20:16:02 INFO RequestMappingHandlerMapping:190 - Mapped "{[/LoadOthersAction],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.nagesh.testLoad.Controller.LoadController.loadOthersAction(java.lang.String,java.lang.String,java.lang.String,java.lang.String,javax.servlet.http.HttpSession)
2015-03-05 20:16:02 INFO RequestMappingHandlerMapping:190 - Mapped "{[/LoadOthersAction2],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.nagesh.testLoad.Controller.LoadController.loadOthersAction2(java.lang.String,java.lang.String,java.lang.String,java.lang.String,javax.servlet.http.HttpSession)
2015-03-05 20:16:02 INFO Version:17 - HV000001: Hibernate Validator 5.2.0.Alpha1
2015-03-05 20:16:03 INFO DispatcherServlet:463 - FrameworkServlet 'SpringApp': initialization completed in 1399 ms
Try setting the spring logging level to error or warn based on your need like below.
log4j.logger.org.springframework=ERROR
You can use SLF4J as facade if you make out with multiple loggers(log4j, springs commons-logging, javautil's logging). For more details slf4j explanation
I am using Spring boot starter project with maving pluging,
spring boot can't know the links in my HTML templates.
this is my controller :
#Controller
#EnableAutoConfiguration
#ComponentScan
public class Demoproject2Application {
#RequestMapping("/")
public String home() {
return "/html/Authentification";
}
}
and this is the Authentification.HTML:
<!DOCTYPE html>
<html>
<head>
<title>Authentification</title>
<link rel="stylesheet" type="text/css" href="css/style2.css" />
and this is the error :
2015-02-19 14:29:58.749 INFO 5136 --- [nio-8090-exec-1] o.a.c.c.C.[Tomcat]. [localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2015-02-19 14:29:58.749 INFO 5136 --- [nio-8090-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2015-02-19 14:29:58.774 INFO 5136 --- [nio-8090-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 25 ms
2015-02-19 14:29:59.086 WARN 5136 --- [nio-8090-exec-2] o.s.web.servlet.PageNotFound : No mapping found for HTTP request with URI [/css/style2.css] in DispatcherServlet with name 'dispatcherServlet'
2015-02-19 14:30:00.813 WARN 5136 --- [nio-8090-exec-4]o.s.web.servlet.PageNotFound
here is a snapshot of the hierarchy of my project :
https://fbcdn-sphotos-f-a.akamaihd.net/hphotos-ak-xfp1/v/t1.0-9/11011221_811266045595770_3095529215585152558_n.jpg?oh=a51a1196651bd62c81a76679869c1bdd&oe=558FD62B&gda=1431221666_e2d5202a80db81801ed9903c48014130
If you didn't changed any defaults it should be served when you put it into src/main/resources/static/css/style2.css. Please see official documentation.