Request method 'GET' not supported in Dockerized SpringBoot REST api - java

I have a small spring application as shown below:
package com.example.demo.api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
#RequestMapping("api/factorial")
#RestController
public class TestApi {
#GetMapping
public long factorial(){
long startTime = System.nanoTime();
int i;
double fact=1;
int number=50;//It is the number to calculate factorial
for(i=1;i<=number;i++){
fact=fact*i;
System.out.println("Factorial of "+i+" is: "+fact);
}
long endTime = System.nanoTime();
return (endTime - startTime);
}
}
I have generated a jar of this application and dockerized it as shown below:
FROM openjdk:8-jdk-alpine
ADD ./demo-0.0.1-SNAPSHOT.jar /usr/src/factorial/
WORKDIR /usr/src/factorial
EXPOSE 8080
CMD java -XX:+PrintFlagsFinal $JAVA_OPTIONS -jar demo-0.0.1-SNAPSHOT.jar
I then run the below command run the docker container
docker run --rm --name factorialContainer -p 8080:8080 -e JAVA_OPTIONS="$(cat jvmFlags.txt)" suleka96/factorial:latest
Then I am trying to make a HTTP request to the REST endpoint using JMeter as shown below
The problem is that when i do this I get an error saying:
org.springframework.web.HttpRequestMethodNotSupportedException:
Request method 'GET' not supported
However, when I run the spring application locally (without dockerizing it)
and send a request from JMeter, the request successfully gets sent.
What am I doing wrong?

Your application is deployed in docker, so it is virtual machine. That is another host with it's own ip address. But you are trying to send GET request to localhost. You should get your docker ip.
Type this to get ip in Mac OS
host> docker-machine ip default
Visit that page https://spring.io/guides/gs/spring-boot-docker/ there's a section about mac os deployment in that knowledge base

The reason behind this has got to be in the logs.
Here's my setup, I changed the controller so it would return json rather than the long primitive:
Controller
#RequestMapping("api/factorial")
#RestController
public class TestApi {
#GetMapping
public Map<String, Long> factorial(){
long startTime = System.nanoTime();
int i;
double fact=1;
int number=50;//It is the number to calculate factorial
for(i=1;i<=number;i++){
fact=fact*i;
System.out.println("Factorial of "+i+" is: "+fact);
}
long endTime = System.nanoTime();
Map<String, Long> res = new HashMap<String, Long>();
res.put("time_in_nanos", (endTime - startTime));
return res;
}
}
Application
#SpringBootApplication(scanBasePackages = "com.example.demo")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
pom
ml 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>demo</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<properties>
<springboot.version>2.0.8.RELEASE</springboot.version>
</properties>
<dependencies>
<!-- Springboot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>${springboot.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>${springboot.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${springboot.version}</version>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${springboot.version}</version>
<executions>
<execution>
<goals>
<goal>build-info</goal>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Docker command line
docker run --rm --name apiTest -p 8080:8080 321225ee07bb
I used your Dockerfile pretty much as is
Log out put from the container:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.8.RELEASE)
2020-02-04 22:55:03.774 INFO 1 --- [ main] com.example.demo.api.Application : Starting Application on 33f1f71d079b with PID 1 (/usr/src/factorial/demo-1.0.jar started by root in /usr/src/factorial)
2020-02-04 22:55:03.796 INFO 1 --- [ main] com.example.demo.api.Application : No active profile set, falling back to default profiles: default
2020-02-04 22:55:04.076 INFO 1 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#2f410acf: startup date [Tue Feb 04 22:55:04 GMT 2020]; root of context hierarchy
2020-02-04 22:55:08.891 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-02-04 22:55:09.002 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-02-04 22:55:09.004 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.37
2020-02-04 22:55:09.055 INFO 1 --- [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/lib/jvm/java-1.8-openjdk/jre/lib/amd64/server:/usr/lib/jvm/java-1.8-openjdk/jre/lib/amd64:/usr/lib/jvm/java-1.8-openjdk/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
2020-02-04 22:55:09.305 INFO 1 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-02-04 22:55:09.307 INFO 1 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 5236 ms
2020-02-04 22:55:10.617 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2020-02-04 22:55:10.626 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'webMvcMetricsFilter' to: [/*]
2020-02-04 22:55:10.636 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2020-02-04 22:55:10.641 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2020-02-04 22:55:10.645 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2020-02-04 22:55:10.647 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpTraceFilter' to: [/*]
2020-02-04 22:55:10.649 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2020-02-04 22:55:11.290 INFO 1 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-02-04 22:55:11.658 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#2f410acf: startup date [Tue Feb 04 22:55:04 GMT 2020]; root of context hierarchy
2020-02-04 22:55:11.864 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/factorial],methods=[GET]}" onto public java.util.Map<java.lang.String, java.lang.Long> com.example.demo.api.TestApi.factorial()
2020-02-04 22:55:11.879 INFO 1 --- [ 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)
2020-02-04 22:55:11.880 INFO 1 --- [ 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)
2020-02-04 22:55:11.960 INFO 1 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-02-04 22:55:11.962 INFO 1 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-02-04 22:55:12.745 INFO 1 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
2020-02-04 22:55:12.787 INFO 1 --- [ main] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped "{[/actuator/health],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.String>)
2020-02-04 22:55:12.792 INFO 1 --- [ main] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped "{[/actuator/info],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.String>)
2020-02-04 22:55:12.796 INFO 1 --- [ main] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped "{[/actuator],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto protected java.util.Map<java.lang.String, java.util.Map<java.lang.String, org.springframework.boot.actuate.endpoint.web.Link>> org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping.links(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2020-02-04 22:55:12.950 INFO 1 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2020-02-04 22:55:13.124 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-02-04 22:55:13.135 INFO 1 --- [ main] com.example.demo.api.Application : Started Application in 10.73 seconds (JVM running for 12.233)
What I'd look for is the mapping of the GET request like this:
2020-02-04 22:55:11.864 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/factorial],methods=[GET]}" onto public java.util.Map<java.lang.String, java.lang.Long> com.example.demo.api.TestApi.factorial()

Related

Table not found error while starting my spring boot application using JPA and derby database

i am creating a very simple spring boot application. I have a topic class which is an entity and i have written a service called TopicService and using CrudRepository methods to do crud operation. When i am starting my application i am getting below message in my consol.:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.4.2.RELEASE)
2019-11-19 22:38:59.611 INFO 9476 --- [ main] i.j.s.CourseApiDataApplication : Starting CourseApiDataApplication on DESKTOP-EL3JT6U with PID 9476 (C:\Users\HP\LearnSpringBoot\Course-api-data\target\classes started by HP in C:\Users\HP\LearnSpringBoot\Course-api-data)
2019-11-19 22:38:59.656 INFO 9476 --- [ main] i.j.s.CourseApiDataApplication : No active profile set, falling back to default profiles: default
2019-11-19 22:38:59.821 INFO 9476 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#64cd705f: startup date [Tue Nov 19 22:38:59 PST 2019]; root of context hierarchy
2019-11-19 22:39:03.887 INFO 9476 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$1f7adbdb] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-11-19 22:39:05.050 INFO 9476 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2019-11-19 22:39:05.069 INFO 9476 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2019-11-19 22:39:05.073 INFO 9476 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.6
2019-11-19 22:39:05.330 INFO 9476 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-11-19 22:39:05.331 INFO 9476 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 5514 ms
2019-11-19 22:39:05.734 INFO 9476 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2019-11-19 22:39:05.743 INFO 9476 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-11-19 22:39:05.743 INFO 9476 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-11-19 22:39:05.747 INFO 9476 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2019-11-19 22:39:05.747 INFO 9476 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2019-11-19 22:39:06.217 INFO 9476 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2019-11-19 22:39:06.258 INFO 9476 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-11-19 22:39:06.452 INFO 9476 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.0.11.Final}
2019-11-19 22:39:06.453 INFO 9476 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2019-11-19 22:39:06.458 INFO 9476 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2019-11-19 22:39:06.563 INFO 9476 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2019-11-19 22:39:08.653 INFO 9476 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.DerbyTenSevenDialect
2019-11-19 22:39:10.542 INFO 9476 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000228: Running hbm2ddl schema update
2019-11-19 22:39:10.732 INFO 9476 --- [ main] rmationExtractorJdbcDatabaseMetaDataImpl : HHH000262: Table not found: Topic
2019-11-19 22:39:10.745 INFO 9476 --- [ main] rmationExtractorJdbcDatabaseMetaDataImpl : HHH000262: Table not found: Topic
2019-11-19 22:39:11.101 INFO 9476 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-11-19 22:39:12.429 INFO 9476 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#64cd705f: startup date [Tue Nov 19 22:38:59 PST 2019]; root of context hierarchy
2019-11-19 22:39:12.614 INFO 9476 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/topics/{id}],methods=[PUT]}" onto public void io.javabrains.springbootstarter.Topic.TopicController.updateTopic(io.javabrains.springbootstarter.Topic.Topic,int)
2019-11-19 22:39:12.614 INFO 9476 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/topics],methods=[POST]}" onto public void io.javabrains.springbootstarter.Topic.TopicController.addTopic(io.javabrains.springbootstarter.Topic.Topic)
2019-11-19 22:39:12.618 INFO 9476 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/topics/{id}],methods=[DELETE]}" onto public void io.javabrains.springbootstarter.Topic.TopicController.deleteTopic(int)
2019-11-19 22:39:12.619 INFO 9476 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/topics/{id}]}" onto public io.javabrains.springbootstarter.Topic.Topic io.javabrains.springbootstarter.Topic.TopicController.getSingleTopic(int)
2019-11-19 22:39:12.619 INFO 9476 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/topics]}" onto public java.util.List<io.javabrains.springbootstarter.Topic.Topic> io.javabrains.springbootstarter.Topic.TopicController.getAllTopics()
2019-11-19 22:39:12.623 INFO 9476 --- [ 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)
2019-11-19 22:39:12.623 INFO 9476 --- [ 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)
2019-11-19 22:39:12.704 INFO 9476 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-11-19 22:39:12.704 INFO 9476 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-11-19 22:39:12.880 INFO 9476 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-11-19 22:39:13.401 INFO 9476 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2019-11-19 22:39:13.676 INFO 9476 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2019-11-19 22:39:13.685 INFO 9476 --- [ main] i.j.s.CourseApiDataApplication : Started CourseApiDataApplication in 15.081 seconds (JVM running for 15.919)
Topic class :
package io.javabrains.springbootstarter.Topic;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name = "Topic")
public class Topic {
#Id
private int id;
private String name;
private String description;
public Topic() {
}
public Topic(int id, String name, String description) { super(); this.id = id;
this.name = name; this.description = description; }
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDesc() {
return description;
}
public void setDesc(String desc) {
this.description = desc;
}
}
TopicService class :used for performing crud operations on topic entity
package io.javabrains.springbootstarter.Topic;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.springframework.stereotype.Service;
#Service
public class TopicService {
private TopicRepository topicRepository;
public List<Topic> getAllTopics(){
List<Topic> lst = new ArrayList<>();
topicRepository.findAll().forEach(lst:: add);
return lst;
}
public Topic getTopic(int id) {
return topicRepository.findOne(id);
//return topicList.stream().filter(t -> t.getName().equals(name)).findFirst().get();
}
public void addTopic(Topic topic) {
topicRepository.save(topic);
//topicList.add(topic);
}
public void updateTopic(Topic topic , int id) {
topicRepository.save(topic);//we do not need another method for update , save method can do both insert and update . it checks firsst
// whether id of topic object is already there in table if it finds the id , it updats it otherwise insert
//topicList.set(id-1 , topic);
}
public void deleteTopic(int id) {
/*for(int i=1; i<=topicList.size(); i++) {
topicList.removeIf(t->t.getId()==id);
}*/
topicRepository.delete(id);
}
}
pom.xml:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>io.javarbrains</groupId>
<artifactId>Course-api-data</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Course-api-data</name>
<description>Demo project for Spring Boot api with data</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.4.Final</version>
</dependency>
-->
<!-- <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.3.Final</version>
</dependency>
-->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.properties
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
The one thing you missed is database connection URL.
Add this to your application.properties file.
spring.datasource.url=jdbc:derby:mydb;create=true
The solution you can apply here is to add the following parameter to the application.properties file.
spring.datasource.initialization-mode=always

spring data RepositoryRestResource not being mapped to endpoints in spring boot app

I've been trying to set up a rest service using spring data rest and spring boot. I followed the tutorial at https://spring.io/guides/gs/accessing-data-rest/ but the expected rest endpoints were not created on startup, and calling get methods on them only led to a 404. I can create an endpoint with RestController, but not with RepositoryRestResource. I am using Spring Boot 2 and hibernate 5.2, with postgres as the backing datastore. I am using eclipse, and have tried running the application via Run Java Application in eclipse, as well as running it from the windows command line using java -jar. The output and end result is the same. Does anybody know what I'm doing wrong and what I need to do for the expected endpoints to be created by the RepositoryRestResource? I've put example code below, with the spring boot output at the bottom, but first here are some similar questions and what I've tried:
this question has an accepted answer which seems to suggest its an entity scanning issue. However, I have added EntityScan to the Application and that didn't seem to help.
RepositoryRestResource with spring-boot CLI
this question has an answer suggesting wrapping the repository in a controller class with RestController instead of using RepositoryRestResource. I can do that, but I don't want to write all the extra code, I would rather that RepositoryRestResource work instead.
Clueless what I'm doing wrong setting up Spring Boot REST app
project structure:
pom.xml
src/main/java/com/springdataresttest/
Application.java
src/main/java/com/springdataresttest/entity/
Thing.java
src/main/java/com/springdataresttest/repository/
ThingRepository.java
src/main/resources/
application.properties
hibernate.properties
postgres ddl:
CREATE TABLE thing
(
id serial,
name varchar(255),
PRIMARY KEY (id)
)
pom.xml:
<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.springdataresttest</groupId>
<artifactId>springdataresttest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</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>
Application.java:
package com.springdataresttest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
#SpringBootApplication
#EntityScan(basePackages = {"com.springdataresttest.entity"})
public class Application {
public static void main(String[] args){
SpringApplication.run(Application.class, args);
}
}
Thing.java:
package com.springdataresttest.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name = "thing")
public class Thing {
private Integer id;
private String name;
#Id
#Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
#Column(name = "name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
ThingRepository.java:
package com.springdataresttest.repository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import com.springdataresttest.entity.Thing;
#RepositoryRestResource(collectionResourceRel = "things", path = "things")
public interface ThingRepository extends PagingAndSortingRepository<Thing, Integer>{
}
application.properties:
security.basic.enabled=false
management.security.enabled=false
security.ignored=/**
spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/springdataresttest
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.username=postgres
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=none
spring.datasource.platform=POSTGRESQL
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.properties:
hibernate.connection.driver_class=org.postgresql.Driver
hibernate.connection.url=jdbc:postgresql://127.0.0.1:5432/springdataresttest
hibernate.connection.username=postgres
hibernate.connection.password=password
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.schema=public
output from spring boot (notice that rest repository endpoints for "things" are not mapped)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.3.RELEASE)
2018-08-23 14:57:51.118 INFO 1336 --- [ main] com.springdataresttest.Application : Starting Application on LTW10me with PID 1336 (C:\Users\me.HQ\workspace\springdataresttest\target\classes started by me in C:\Users\me.HQ\workspace\springdataresttest)
2018-08-23 14:57:51.123 INFO 1336 --- [ main] com.springdataresttest.Application : No active profile set, falling back to default profiles: default
2018-08-23 14:57:51.233 INFO 1336 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#6646153: startup date [Thu Aug 23 14:57:51 EDT 2018]; root of context hierarchy
2018-08-23 14:57:52.882 INFO 1336 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$ca53dd09] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-08-23 14:57:53.548 INFO 1336 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2018-08-23 14:57:53.583 INFO 1336 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-08-23 14:57:53.583 INFO 1336 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.31
2018-08-23 14:57:53.593 INFO 1336 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_112\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre1.8.0_171/bin/server;C:/Program Files/Java/jre1.8.0_171/bin;C:/Program Files/Java/jre1.8.0_171/lib/amd64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\PuTTY\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Bitvise SSH Client;C:\Program Files\TortoiseGit\bin;C:\Program Files\Git\cmd;C:\Program Files (x86)\Yarn\bin\;C:\Program Files\nodejs\;C:\WINDOWS\System32\OpenSSH\;"C:\Users\me.HQ\AppData\Local\Microsoft\WindowsApps;C:\Program Files (x86)\PuTTY;C:\Program Files\PostgreSQL\9.6\bin;C:\cygwin64;C;\cygwin64\bin;";C:\Users\me.HQ\AppData\Local\Microsoft\WindowsApps;;C:\Program Files\Microsoft VS Code\bin;C:\Users\me.HQ\AppData\Local\Yarn\bin;C:\Users\me.HQ\AppData\Roaming\npm;C:\eclipse;;.]
2018-08-23 14:57:53.709 INFO 1336 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-08-23 14:57:53.709 INFO 1336 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2481 ms
2018-08-23 14:57:53.876 INFO 1336 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2018-08-23 14:57:53.881 INFO 1336 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-08-23 14:57:53.881 INFO 1336 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-08-23 14:57:53.881 INFO 1336 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-08-23 14:57:53.886 INFO 1336 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-08-23 14:57:54.138 INFO 1336 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2018-08-23 14:57:54.720 INFO 1336 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2018-08-23 14:57:54.768 INFO 1336 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2018-08-23 14:57:54.793 INFO 1336 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2018-08-23 14:57:54.944 INFO 1336 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.2.17.Final}
2018-08-23 14:57:54.947 INFO 1336 --- [ main] org.hibernate.cfg.Environment : HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.username=postgres, hibernate.schema=public, hibernate.connection.password=****, hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect, hibernate.connection.url=jdbc:postgresql://127.0.0.1:5432/springdataresttest, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.driver_class=org.postgresql.Driver}
2018-08-23 14:57:55.015 INFO 1336 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2018-08-23 14:57:55.155 WARN 1336 --- [ main] o.h.e.j.e.i.JdbcEnvironmentInitiator : HHH000342: Could not obtain connection to query metadata : null
2018-08-23 14:57:55.168 INFO 1336 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2018-08-23 14:57:55.188 INFO 1336 --- [ main] o.h.e.j.e.i.LobCreatorBuilderImpl : HHH000422: Disabling contextual LOB creation as connection was null
2018-08-23 14:57:55.193 INFO 1336 --- [ main] org.hibernate.type.BasicTypeRegistry : HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType#64f16277
2018-08-23 14:57:55.716 INFO 1336 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-08-23 14:57:55.851 INFO 1336 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-23 14:57:56.594 INFO 1336 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#6646153: startup date [Thu Aug 23 14:57:51 EDT 2018]; root of context hierarchy
2018-08-23 14:57:56.653 WARN 1336 --- [ main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2018-08-23 14:57:56.698 INFO 1336 --- [ 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-08-23 14:57:56.703 INFO 1336 --- [ 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-08-23 14:57:56.748 INFO 1336 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-23 14:57:56.749 INFO 1336 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-23 14:57:57.112 INFO 1336 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-08-23 14:57:57.115 INFO 1336 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure
2018-08-23 14:57:57.120 INFO 1336 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2018-08-23 14:57:57.170 INFO 1336 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-08-23 14:57:57.180 INFO 1336 --- [ main] com.springdataresttest.Application : Started Application in 6.496 seconds (JVM running for 6.954)

Rest Controller not Working

I have initialed spring boot project using start.spring.io and added WEB,JPA,H2 dependencies.
Pom 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>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.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>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<!-- <scope>runtime</scope> -->
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
application.properties
spring.h2.console.enabled=true
security.basic.enabled=false
DemoApplication.java
#SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
UserController.java
#RestController
public class UserController {
#GetMapping("/hello")
public String hello() {
return "Hello";
}
Console Log
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.10.RELEASE)
2018-02-26 11:24:28.846 INFO 4792 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication on RAJAT-PC with PID 4792 (C:\Users\devra\Downloads\Compressed\demo\target\classes started by rajat in C:\Users\devra\Downloads\Compressed\demo)
2018-02-26 11:24:28.855 INFO 4792 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2018-02-26 11:24:29.018 INFO 4792 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#6b67034: startup date [Mon Feb 26 11:24:29 IST 2018]; root of context hierarchy
2018-02-26 11:24:30.894 INFO 4792 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$fa7e8c5a] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-02-26 11:24:31.720 INFO 4792 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2018-02-26 11:24:31.737 INFO 4792 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-02-26 11:24:31.740 INFO 4792 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.27
2018-02-26 11:24:31.969 INFO 4792 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-02-26 11:24:31.970 INFO 4792 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2957 ms
2018-02-26 11:24:32.307 INFO 4792 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-02-26 11:24:32.308 INFO 4792 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-02-26 11:24:32.309 INFO 4792 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-02-26 11:24:32.309 INFO 4792 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-02-26 11:24:32.310 INFO 4792 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2018-02-26 11:24:32.311 INFO 4792 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2018-02-26 11:24:32.313 INFO 4792 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'webServlet' to [/h2-console/*]
2018-02-26 11:24:33.004 INFO 4792 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2018-02-26 11:24:33.038 INFO 4792 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2018-02-26 11:24:33.196 INFO 4792 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.0.12.Final}
2018-02-26 11:24:33.199 INFO 4792 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2018-02-26 11:24:33.202 INFO 4792 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2018-02-26 11:24:33.266 INFO 4792 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2018-02-26 11:24:33.517 INFO 4792 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2018-02-26 11:24:33.807 INFO 4792 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000227: Running hbm2ddl schema export
2018-02-26 11:24:33.816 INFO 4792 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000230: Schema export complete
2018-02-26 11:24:33.859 INFO 4792 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-02-26 11:24:34.365 INFO 4792 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#6b67034: startup date [Mon Feb 26 11:24:29 IST 2018]; root of context hierarchy
2018-02-26 11:24:34.506 INFO 4792 --- [ 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)
2018-02-26 11:24:34.508 INFO 4792 --- [ 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)
2018-02-26 11:24:34.568 INFO 4792 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-02-26 11:24:34.569 INFO 4792 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-02-26 11:24:34.663 INFO 4792 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-02-26 11:24:35.147 INFO 4792 --- [ main] b.a.s.AuthenticationManagerConfiguration :
Using default security password: dd5212d7-4de1-4fee-9f6b-f5cd888f2f17
2018-02-26 11:24:35.222 INFO 4792 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: OrRequestMatcher [requestMatchers=[Ant [pattern='/css/**'], Ant [pattern='/js/**'], Ant [pattern='/images/**'], Ant [pattern='/webjars/**'], Ant [pattern='/**/favicon.ico'], Ant [pattern='/error']]], []
2018-02-26 11:24:35.334 INFO 4792 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: org.springframework.boot.autoconfigure.security.SpringBootWebSecurityConfiguration$ApplicationNoWebSecurityConfigurerAdapter$1#11c713b7, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#2251b3bc, org.springframework.security.web.context.SecurityContextPersistenceFilter#602f8f94, org.springframework.security.web.header.HeaderWriterFilter#2785db06, org.springframework.security.web.csrf.CsrfFilter#603cabc4, org.springframework.security.web.authentication.logout.LogoutFilter#7a9ceddf, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#4dfe8b37, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#7e64c1a9, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#3fbe503c, org.springframework.security.web.session.SessionManagementFilter#715a70e9, org.springframework.security.web.access.ExceptionTranslationFilter#1cc8416a]
2018-02-26 11:24:35.552 INFO 4792 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-02-26 11:24:35.652 INFO 4792 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2018-02-26 11:24:35.670 INFO 4792 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 7.302 seconds (JVM running for 7.824)
as you can see spring didn't mapped the /hello url
Considering that the other answers don't explain why it doesn't work as expected, here's why.
Spring uses component scanning to find eligible beans (#Repository, #Service, #Component, #Controller, ...). This is usually done by using the #ComponentScan annotation.
This is explained in the core docs:
To autodetect these classes and register the corresponding beans, you need to add #ComponentScan to your #Configuration class, where the basePackages attribute is a common parent package for the two classes. (Alternatively, you can specify a comma/semicolon/space-separated list that includes the parent package of each class.)
Spring Boot, by default only scans components within the same package (and including subpackages) of the main class. This is because the #SpringBootApplication annotation includes a #ComponentScanby default, as mentioned in the Spring boot docs:
The #SpringBootApplication annotation is equivalent to using #Configuration, #EnableAutoConfiguration and #ComponentScan with their default attributes
If you want Spring to automatically detect your controller, you have three options:
Move the controller to the com.example.demo package. This is the recommended approach according to the Spring boot documentation.
Telling Spring to look at the controller package by adding a #ComponentScan annotation:
#SpringBootApplication
#ComponentScan({"com.example.demo", "controller"}) // Add this
public class DemoApplication {
// ...
}
Telling Spring to look at the controller package by configuring the scanBasePackages property of #SpringBootApplication:
#SpringBootApplication(scanBasePackages = {"com.example.demo", "controller"}) // Add this
public class DemoApplication {
// ...
}
Spring reference doc says - Generally recommend that you locate your main application class in a root package above other classes like
com
+- example
+- myproject
+- Application.java
|
+- domain
| +- Customer.java
| +- CustomerRepository.java
|
+- service
| +- CustomerService.java
|
+- web
+- CustomerController.java
For more refer this link :
https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-structuring-your-code.html

All Spring-Boot Application always show a popup login

I'm using Spring and Spring Boot framework with Spring Security for a simple login projects with simple UI. In all my projects, using STS, after starting my application and run the localhost address without errors, i receive a popup login window and not my html page.
If i use user and default security password i always get a Whitelabel Error Page as results. Furthermore, if i use incorrect value the popup remain, if instead i use the default access value i get this message.
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Aug 23 20:14:22 CEST 2017
There was an unexpected error (type=Not Found, status=404).
No message available
Here is a simple project code. All the html files are in template folder as you can see in project structure. I also try to use server.error.whitelabel.enabled=false in my application.properties file.`
Why has the html interface never been shown?
Project Structure
Application
package com.cyberdemon.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class SpringbootUiLoginApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootUiLoginApplication.class, args);
}
}
SecurityConfig
package config;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
#Configuration
#EnableAutoConfiguration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
#Autowired
DataSource dataSource;
#Autowired
public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(dataSource)
.usersByUsernameQuery("select username,password, enabled from users where username=?")
.authoritiesByUsernameQuery("select username, role from user_roles where username=?");
}
#Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/", "/home").permitAll().antMatchers("/admin").hasRole("ADMIN")
.anyRequest().authenticated().and().formLogin().loginPage("/login").permitAll().and().logout()
.permitAll();
http.exceptionHandling().accessDeniedPage("/403");
}
}
WebController
package controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class WebController {
#RequestMapping(value = { "/", "home" })
public String home() {
return "home";
}
#RequestMapping(value = { "/welcome" })
public String welcome() {
return "welcome";
}
#RequestMapping(value = "/admin")
public String admin() {
return "admin";
}
#RequestMapping(value = { "/login" })
public String login() {
return "login";
}
#RequestMapping(value = "/403")
public String Error403() {
return "403";
}
}
Pom
<?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.cyberdemon.springboot</groupId>
<artifactId>springboot_UI_Login</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>springboot_UI_Login</name>
<description>Project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.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>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-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>
properties
spring.datasource.url=jdbc:mysql://localhost:3306/testdb
spring.datasource.username=root
spring.datasource.password=toor
Console
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.6.RELEASE)
2017-08-23 19:57:05.949 INFO 7496 --- [ main] c.c.s.SpringbootUiLoginApplication : Starting SpringbootUiLoginApplication on DESKTOP-CYBERDEMON with PID 7496 (started by GD in C:\Users\me\Documents\workspace-sts\springboot_ui_login)
2017-08-23 19:57:05.949 INFO 7496 --- [ main] c.c.s.SpringbootUiLoginApplication : No active profile set, falling back to default profiles: default
2017-08-23 19:57:06.121 INFO 7496 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#6cc7b4de: startup date [Wed Aug 23 19:57:06 CEST 2017]; root of context hierarchy
2017-08-23 19:57:07.293 INFO 7496 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-08-23 19:57:07.300 INFO 7496 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2017-08-23 19:57:07.300 INFO 7496 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.16
2017-08-23 19:57:07.409 INFO 7496 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-08-23 19:57:07.409 INFO 7496 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1288 ms
2017-08-23 19:57:07.566 INFO 7496 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-08-23 19:57:07.566 INFO 7496 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-08-23 19:57:07.566 INFO 7496 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-08-23 19:57:07.566 INFO 7496 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2017-08-23 19:57:07.566 INFO 7496 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2017-08-23 19:57:07.566 INFO 7496 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-08-23 19:57:07.847 INFO 7496 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#6cc7b4de: startup date [Wed Aug 23 19:57:06 CEST 2017]; root of context hierarchy
2017-08-23 19:57:07.894 INFO 7496 --- [ 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-08-23 19:57:07.894 INFO 7496 --- [ 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-08-23 19:57:07.925 INFO 7496 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-08-23 19:57:07.925 INFO 7496 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-08-23 19:57:07.956 INFO 7496 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-08-23 19:57:08.519 INFO 7496 --- [ main] b.a.s.AuthenticationManagerConfiguration :
Using default security password: 21cf3953-b4e3-48ac-87fa-9041c41b3ff8
2017-08-23 19:57:08.567 INFO 7496 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: OrRequestMatcher [requestMatchers=[Ant [pattern='/css/**'], Ant [pattern='/js/**'], Ant [pattern='/images/**'], Ant [pattern='/webjars/**'], Ant [pattern='/**/favicon.ico'], Ant [pattern='/error']]], []
2017-08-23 19:57:08.645 INFO 7496 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: OrRequestMatcher [requestMatchers=[Ant [pattern='/**']]], [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#12fcc71f, org.springframework.security.web.context.SecurityContextPersistenceFilter#5d43409a, org.springframework.security.web.header.HeaderWriterFilter#76563d26, org.springframework.security.web.authentication.logout.LogoutFilter#102ecc22, org.springframework.security.web.authentication.www.BasicAuthenticationFilter#4eba373c, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#6ede46f6, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#10a0fe30, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#5679e96b, org.springframework.security.web.session.SessionManagementFilter#23b8d9f3, org.springframework.security.web.access.ExceptionTranslationFilter#261ea657, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#6cd64ee8]
2017-08-23 19:57:08.864 INFO 7496 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-08-23 19:57:08.911 INFO 7496 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-08-23 19:57:08.926 INFO 7496 --- [ main] c.c.s.SpringbootUiLoginApplication : Started SpringbootUiLoginApplication in 3.164 seconds (JVM running for 3.428)
2017-08-23 19:57:24.008 INFO 7496 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2017-08-23 19:57:24.008 INFO 7496 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2017-08-23 19:57:24.021 INFO 7496 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 13 ms
You need to restructure your packages to that they fall under the package of your SpringbootUiLoginApplication or use #ComponentScan to tell the Spring Boot where to find your bean classes.
Following up on Ali's answer:
#SpringBootApplication implies #Configuration , #EnableAutoConfiguration and #ComponentScan
So, consider changing:
#Configuration
#EnableAutoConfiguration
public class SecurityConfig extends WebSecurityConfigurerAdapter
to:
#Component
public class SecurityConfig extends WebSecurityConfigurerAdapter
And to scan for beans in your entire package change:
#SpringBootApplication
public class SpringbootUiLoginApplication
to:
#SpringBootApplication
#ComponentScan("com.cyberdemon")
public class SpringbootUiLoginApplication
I got this when I didn't realize another Spring Boot application was running on port 8080. End that and you won't get that security modal.

How to configure spring-boot with embedded Tomcat to work as a single application?

I have application which after mvn clean package -U tomcat7:run works as soap web service and wsdl is available on: http://localhost:8080/appservices/ws?wsdl
Now my aim to compile a single jar which will provide web service after execute java -jar service.jar.
As I know spring-boot decides this task.
I created an Application class:
package com.comp.service;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
#Configuration
#ComponentScan
#EnableAutoConfiguration
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}
But after I execute mvn spring-boot:run and call url http://localhost:8080/appservices/ws?wsdl I receive:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri Feb 05 14:54:11 MSK 2016
There was an unexpected error (type=Not Found, status=404).
No message available
Spring's start log:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.3.2.RELEASE)
2016-02-05 14:43:45.012 INFO 21008 --- [ main] com.comp.service.Application : Starting Application on PCwith PID 21008 (C:\Users\Maya\git\app-services\target\classes started by Maya in C:\Users\Maya\git\app-services
-services)
2016-02-05 14:43:45.017 INFO 21008 --- [ main] com.comp.service.Application : No active profile set, falling back to default profiles: default
2016-02-05 14:43:45.117 INFO 21008 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#5dc33359: startup date [Fri Feb 05 14:43:45 MSK 2016]; root o
f context hierarchy
2016-02-05 14:43:46.344 INFO 21008 --- [ 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=fal
se; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; des
troyMethodName=(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; depen
dencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); de
fined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
2016-02-05 14:43:47.363 INFO 21008 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-02-05 14:43:47.386 INFO 21008 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2016-02-05 14:43:47.388 INFO 21008 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.30
2016-02-05 14:43:47.555 INFO 21008 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2016-02-05 14:43:47.559 INFO 21008 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2448 ms
2016-02-05 14:43:48.048 INFO 21008 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2016-02-05 14:43:48.055 INFO 21008 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-02-05 14:43:48.055 INFO 21008 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-02-05 14:43:48.056 INFO 21008 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-02-05 14:43:48.057 INFO 21008 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2016-02-05 14:43:48.475 INFO 21008 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#5dc33359: startup date [Fri Feb 05 14:43:
45 MSK 2016]; root of context hierarchy
2016-02-05 14:43:48.589 INFO 21008 --- [ 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.autoconfigur
e.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2016-02-05 14:43:48.592 INFO 21008 --- [ 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.BasicErrorControlle
r.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2016-02-05 14:43:48.639 INFO 21008 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-02-05 14:43:48.639 INFO 21008 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-02-05 14:43:48.694 INFO 21008 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-02-05 14:43:48.869 INFO 21008 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-02-05 14:43:48.967 INFO 21008 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-02-05 14:43:48.972 INFO 21008 --- [ main] com.comp.service.Application : Started Application in 4.428 seconds (JVM running for 11.125)
2016-02-05 14:44:02.085 INFO 21008 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2016-02-05 14:44:02.086 INFO 21008 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2016-02-05 14:44:02.107 INFO 21008 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 21 ms
Where is my problem? In Application.class?
My pom:
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jdkName>JavaSE-1.7</jdkName>
<jdk.version>1.7</jdk.version>
<spring-boot.version>1.3.2.RELEASE</spring-boot.version>
<spring.version>4.2.4.RELEASE</spring.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>8080</port>
<extraDependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>1.7.2</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.0.7</version>
</dependency>
</extraDependencies>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<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-tomcat</artifactId>
<version>${spring-boot.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.10</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
</project>
Thank you for any advice.
UPDATE
May be problem in web.xml?:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems,
Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app>
<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener
</listener-class>
</listener>
<servlet>
<servlet-name>WSServlet</servlet-name>
<servlet-class>
<!--com.sun.xml.ws.transport.http.servlet.WSServlet-->
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>WSServlet</servlet-name>
<url-pattern>/ws</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>120</session-timeout>
</session-config>
</web-app>
UPDATE 1:
Application class:
#SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Configuration:
#Configuration
#EnableAutoConfiguration
public class AppConfig {
#Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
factory.setPort(9000);
factory.setSessionTimeout(10, TimeUnit.MINUTES);
factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/notfound.html"));
return factory;
}
}
spring-boot:run log:
2016-02-08 10:26:19.733 INFO 3976 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-02-08 10:26:19.758 INFO 3976 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0
2016-02-08 10:26:19.990 INFO 3976 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 9000 (http)
2016-02-08 10:26:19.998 INFO 3976 --- [ main] com.comp.service.Application : Started Application in 5.911 seconds (JVM running for 15.537)
2016-02-08 10:26:53.130 INFO 3976 --- [nio-9000-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2016-02-08 10:26:53.130 INFO 3976 --- [nio-9000-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2016-02-08 10:26:53.156 INFO 3976 --- [nio-9000-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 26 ms

Categories