I am studying Spring Mvc and Spring Boot and came across the following problem that until now could not identify. After running my main method I get the following message.
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback. Tue Jul 20 21:22:43 BRT 2016 There was an unexpected error (type=Not Found, status=404). No message available
Controller
#Controller
#RequestMapping(value="/restauranteWeb")
public class HomeController {
#RequestMapping(method=RequestMethod.GET)
public String redirect() {
return "login/login";
}
}
Method Main
#SpringBootApplication()
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Configuration
#Configuration
#EnableWebMvc
#ComponentScan(basePackages = "com.gervasios.rsw")
public class ApplicationConfiguration extends WebMvcConfigurerAdapter {
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
#Override
public void configureViewResolvers(ViewResolverRegistry registry) {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/pages/");
viewResolver.setSuffix(".jsp");
registry.viewResolver(viewResolver);
}
}
#Bean
public TilesConfigurer tilesConfigurer() {
TilesConfigurer tilesConfigurer = new TilesConfigurer();
tilesConfigurer.setDefinitions(new String[] {"/**/WEB-INF/**/tiles-config.xml"});
tilesConfigurer.setCheckRefresh(true);
return tilesConfigurer;
}
AppInitializer
public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
#Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] {ApplicationConfiguration.class};
}
#Override
protected Class<?>[] getServletConfigClasses() {
return new Class[0];
}
#Override
protected String[] getServletMappings() {
return new String[] {"/"};
}
}
POM
<!-- Spring BOOT-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
</parent>
<repositories>
<repository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>4.2.5.RELEASE</spring.version>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</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-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- Javax - Jsf -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
LOG localhost:8080/restauranteWeb
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.3.5.RELEASE)
2016-07-21 22:24:17.632 INFO 4576 --- [ main] c.g.r.configuration.ApplicationExecute : Starting ApplicationExecute on Helio-PC with PID 4576 (C:\Users\Helio\git\restauranteWeb\restauranteWeb\target\classes started by Helio in C:\Users\Helio\git\restauranteWeb\restauranteWeb)
2016-07-21 22:24:17.632 INFO 4576 --- [ main] c.g.r.configuration.ApplicationExecute : No active profile set, falling back to default profiles: default
2016-07-21 22:24:17.695 INFO 4576 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#1f32bf7: startup date [Thu Jul 21 22:24:17 BRT 2016]; root of context hierarchy
2016-07-21 22:24:19.433 INFO 4576 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$1e356ee6] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-07-21 22:24:20.124 INFO 4576 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-07-21 22:24:20.139 INFO 4576 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2016-07-21 22:24:20.155 INFO 4576 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.33
2016-07-21 22:24:20.358 INFO 4576 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2016-07-21 22:24:20.358 INFO 4576 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2663 ms
2016-07-21 22:24:20.514 INFO 4576 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2016-07-21 22:24:20.530 INFO 4576 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-07-21 22:24:20.612 INFO 4576 --- [ main] o.s.j.d.DriverManagerDataSource : Loaded JDBC driver: com.mysql.jdbc.Driver
2016-07-21 22:24:21.020 INFO 4576 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2016-07-21 22:24:21.036 INFO 4576 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2016-07-21 22:24:21.129 INFO 4576 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {4.3.11.Final}
2016-07-21 22:24:21.129 INFO 4576 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2016-07-21 22:24:21.129 INFO 4576 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2016-07-21 22:24:21.348 INFO 4576 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2016-07-21 22:24:21.426 INFO 4576 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2016-07-21 22:24:21.489 INFO 4576 --- [ main] o.h.h.i.ast.ASTQueryTranslatorFactory : HHH000397: Using ASTQueryTranslatorFactory
2016-07-21 22:24:21.801 INFO 4576 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2016-07-21 22:24:21.913 INFO 4576 --- [ main] o.h.e.t.i.TransactionFactoryInitiator : HHH000399: Using default transaction strategy (direct JDBC transactions)
2016-07-21 22:24:21.913 INFO 4576 --- [ main] o.h.h.i.ast.ASTQueryTranslatorFactory : HHH000397: Using ASTQueryTranslatorFactory
2016-07-21 22:24:22.100 INFO 4576 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000228: Running hbm2ddl schema update
2016-07-21 22:24:22.100 INFO 4576 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000102: Fetching database metadata
2016-07-21 22:24:22.116 INFO 4576 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000396: Updating schema
2016-07-21 22:24:22.116 INFO 4576 --- [ main] java.sql.DatabaseMetaData : HHH000262: Table not found: RESADM.TUSUARIO
2016-07-21 22:24:22.116 INFO 4576 --- [ main] java.sql.DatabaseMetaData : HHH000262: Table not found: RESADM.TUSUARIO
2016-07-21 22:24:22.116 INFO 4576 --- [ main] java.sql.DatabaseMetaData : HHH000262: Table not found: RESADM.TUSUARIO
2016-07-21 22:24:22.131 ERROR 4576 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000388: Unsuccessful: create table RESADM.TUSUARIO (CODUSUARIO bigint not null auto_increment, DATCAD datetime, LOGIN varchar(255), SENHA varchar(255), SITUACAO varchar(255), primary key (CODUSUARIO))
2016-07-21 22:24:22.131 ERROR 4576 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : Table 'tusuario' already exists
2016-07-21 22:24:22.131 INFO 4576 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000232: Schema update complete
2016-07-21 22:24:22.392 INFO 4576 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/restauranteWeb],methods=[GET]}" onto public java.lang.String com.gervasios.rsw.controller.HomeController.redirect()
2016-07-21 22:24:22.408 INFO 4576 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/principal],methods=[GET]}" onto public java.lang.String com.gervasios.rsw.controller.PrincipalController.principal()
2016-07-21 22:24:22.408 INFO 4576 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/cadastroUsuario],methods=[GET]}" onto public java.lang.String com.gervasios.rsw.controller.UsuarioController.newUser(org.springframework.ui.Model)
2016-07-21 22:24:22.408 INFO 4576 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/cadastrarUsuario],methods=[POST]}" onto public java.lang.String com.gervasios.rsw.controller.UsuarioController.salvar(com.gervasios.rsw.model.Usuario,org.springframework.ui.ModelMap)
2016-07-21 22:24:22.408 INFO 4576 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/usuariosSearch],methods=[GET]}" onto public void com.gervasios.rsw.controller.UsuarioController.buscarUsuarios(org.springframework.ui.Model)
2016-07-21 22:24:22.408 INFO 4576 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2016-07-21 22:24:22.408 INFO 4576 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2016-07-21 22:24:22.439 INFO 4576 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/resources/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-07-21 22:24:22.533 INFO 4576 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#1f32bf7: startup date [Thu Jul 21 22:24:17 BRT 2016]; root of context hierarchy
2016-07-21 22:24:22.611 INFO 4576 --- [ main] o.s.o.h.HibernateTransactionManager : Using DataSource [org.springframework.jdbc.datasource.DriverManagerDataSource#1edc703] of Hibernate SessionFactory for HibernateTransactionManager
2016-07-21 22:24:23.048 INFO 4576 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-07-21 22:24:23.159 INFO 4576 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-07-21 22:24:23.159 INFO 4576 --- [ main] c.g.r.configuration.ApplicationExecute : Started ApplicationExecute in 5.949 seconds (JVM running for 6.325)
2016-07-21 22:24:54.039 INFO 4576 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2016-07-21 22:24:54.039 INFO 4576 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2016-07-21 22:24:54.073 INFO 4576 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 34 ms
2016-07-21 22:24:54.198 WARN 4576 --- [nio-8080-exec-1] o.s.web.servlet.PageNotFound : No mapping found for HTTP request with URI [/WEB-INF/pages/login/login.jsp] in DispatcherServlet with name 'dispatcherServlet'
Related
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
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)
I'm using Spring Boot with Kotlin . The rest controller returns 404 error for all endpoints. In the starting logs the endpoints in the controller are not present. Any endpoint returns the same 404 response.
These are the steps I have tried,
Tried clearing cache/target
Moved all classes into single directory
Tried adding ComponentScan annotation but it is not accepted.
I'm using cmd line to run the project
Same output seen when running java -jar $jarfile
Checked annotations Repository , Service , RestController
Controller:
package com.example.controller
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.PutMapping
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.RequestBody
import Cricketer
import CricketerRepository
import CricketerService
import org.springframework.web.bind.annotation.RequestMapping
#RestController
#RequestMapping("/api")
class CricketerController(private val cricketerService: CricketerService , private val cricketerRepository: CricketerRepository){
#GetMapping("/cricketers/{id}")
fun getCricketer(#PathVariable("id") id: Long):ResponseEntity<Cricketer> {
val cricketer = cricketerService.findById(id)
return ResponseEntity<Cricketer>(cricketer as Cricketer, HttpStatus.OK);
}
#GetMapping("/cricketers/")
fun getAllCricketers() :ResponseEntity<List<Cricketer>> {
var cricketersList: ArrayList<Cricketer> = cricketerService.getAllPlayers() as (ArrayList<Cricketer>)
return ResponseEntity<List<Cricketer>>(cricketersList, HttpStatus.OK)
}
#PostMapping("/cricketer/")
fun addCricketer(#RequestBody cricketer:Cricketer):ResponseEntity<Cricketer> {
val cCricketer : Cricketer = Cricketer(name = cricketer.name
, country = cricketer.country
, highestScore = cricketer.highestScore)
cricketerRepository.save(cCricketer)
return ResponseEntity<Cricketer>(cricketer , HttpStatus.OK)
}
#PutMapping("/cricketer/{id}")
fun updateCricketer(#PathVariable("id") id: Long, #RequestBody cricketer: Cricketer ):ResponseEntity<Cricketer> {
val cCricketer = Cricketer(name = cricketer.name
, country = cricketer.country
, highestScore = cricketer.highestScore)
cricketerRepository.save(cCricketer)
return ResponseEntity<Cricketer>(cricketer, HttpStatus.OK)
}
#DeleteMapping("/cricketer/{id}")
fun deleteCricketer(#PathVariable("id") id:Long ):ResponseEntity<String> {
val cCricketer :Cricketer = cricketerService.findById(id) as Cricketer
cricketerRepository.delete(cCricketer)
return ResponseEntity<String>("cricketer removed", HttpStatus.OK)
}
}
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>Spring-Kotlin-Rest-API</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Spring-Kotlin-Rest-API</name>
<description>Spring Boot Kotlin REST API Example</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.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>
<kotlin.version>1.2.41</kotlin.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>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</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>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
<jvmTarget>1.8</jvmTarget>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Startup logs
2018-05-21 22:31:19.490 INFO 3061 --- [ main] c.e.d.SpringKotlinRestApiApplicationKt : Starting SpringKotlinRestApiApplicationKt on nirmal-desktop with PID 3061 (/home/nirmal/code/workspace-sts-3.9.1.RELEASE/Spring-Kotlin-Rest-API/target/classes started by root in /home/nirmal/code/workspace-sts-3.9.1.RELEASE/Spring-Kotlin-Rest-API)
2018-05-21 22:31:19.512 INFO 3061 --- [ main] c.e.d.SpringKotlinRestApiApplicationKt : No active profile set, falling back to default profiles: default
2018-05-21 22:31:19.592 INFO 3061 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#5bab7c16: startup date [Mon May 21 22:31:19 IST 2018]; root of context hierarchy
2018-05-21 22:31:29.492 INFO 3061 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$28d3b505] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-05-21 22:31:33.847 INFO 3061 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2018-05-21 22:31:34.312 INFO 3061 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-05-21 22:31:34.313 INFO 3061 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.31
2018-05-21 22:31:34.389 INFO 3061 --- [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/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
2018-05-21 22:31:36.190 INFO 3061 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-05-21 22:31:36.190 INFO 3061 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 16602 ms
2018-05-21 22:31:36.560 INFO 3061 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2018-05-21 22:31:36.564 INFO 3061 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-05-21 22:31:36.566 INFO 3061 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-05-21 22:31:36.566 INFO 3061 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-05-21 22:31:36.566 INFO 3061 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-05-21 22:31:37.743 INFO 3061 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2018-05-21 22:31:39.038 INFO 3061 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2018-05-21 22:31:39.222 INFO 3061 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2018-05-21 22:31:39.480 INFO 3061 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2018-05-21 22:31:40.064 INFO 3061 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.2.17.Final}
2018-05-21 22:31:40.066 INFO 3061 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2018-05-21 22:31:40.302 INFO 3061 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2018-05-21 22:31:42.180 INFO 3061 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
2018-05-21 22:31:44.235 INFO 3061 --- [ main] o.h.t.schema.internal.SchemaCreatorImpl : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl#7d95eb4a'
2018-05-21 22:31:44.237 INFO 3061 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-05-21 22:31:44.688 INFO 3061 --- [ 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-21 22:31:46.829 INFO 3061 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#5bab7c16: startup date [Mon May 21 22:31:19 IST 2018]; root of context hierarchy
2018-05-21 22:31:46.894 WARN 3061 --- [ 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-05-21 22:31:47.072 INFO 3061 --- [ 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-21 22:31:47.073 INFO 3061 --- [ 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-21 22:31:47.121 INFO 3061 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-05-21 22:31:47.122 INFO 3061 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-05-21 22:31:49.030 INFO 3061 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-05-21 22:31:49.033 INFO 3061 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure
2018-05-21 22:31:49.047 INFO 3061 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2018-05-21 22:31:50.682 INFO 3061 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-05-21 22:31:50.695 INFO 3061 --- [ main] c.e.d.SpringKotlinRestApiApplicationKt : Started SpringKotlinRestApiApplicationKt in 34.697 seconds (JVM running for 49.043)
I guess your CricketerController is not in a subpackage relative to your main class. So you basically have two options:
Place your main class directly under the package com.example
Add the annotation at the bottom of this answer to your main class.
Using any of these two methods makes the controller class visible for Spring at startup and therefore should create your mappings.
#ComponentScan(basePackages = { "com.example.controller"} )
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
i build it using mvn clean package and get a xxx.jar file.
run $java -jar xxx.jar >> output.log & start it, and it works well.
but about two hours later, it shutdown, why?
here is an answer but don't work for me >>https://stackoverflow.com/a/22409655/1767024
here is my output.log:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.1.9.RELEASE)
2016-03-17 17:41:54.784 INFO 20016 --- [ main] com.hello.bibi.App : Starting App on iZ947723zxnZ with PID 20016 (/root/projects/taomi-back/bibi-0.0.1-SNAPSHOT.jar started by root in /root/projects/taomi-back)
2016-03-17 17:41:54.850 INFO 20016 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#5cf0ac6e: startup date [Thu Mar 17 17:41:54 CST 2016]; root of context hierarchy
2016-03-17 17:41:56.477 INFO 20016 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'beanNameViewResolver': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false;factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
2016-03-17 17:41:57.557 INFO 20016 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'databaseConfig4Bibi' of type [class com.hello.bibi.config.DatabaseConfig4Bibi$$EnhancerBySpringCGLIB$$5c20f114] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-17 17:41:58.434 INFO 20016 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'dataSource4bibi' of type [class com.jolbox.bonecp.BoneCPDataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-17 17:41:59.194 INFO 20016 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'sqlSessionFactory4bibi' of type [class org.apache.ibatis.session.defaults.DefaultSqlSessionFactory] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-17 17:41:59.278 INFO 20016 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'spiderJdCommentIncrMapper' of type [class org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-17 17:41:59.287 INFO 20016 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'spiderJdCommentMapper' of type [class org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-17 17:41:59.294 INFO 20016 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'spiderJdItemMapper' of type [class org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-17 17:41:59.300 INFO 20016 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'userMapper' of type [class org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-17 17:41:59.402 INFO 20016 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$364a7a87] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-17 17:41:59.436 INFO 20016 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'transactionAttributeSource' of type [class org.springframework.transaction.annotation.AnnotationTransactionAttributeSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-17 17:41:59.452 INFO 20016 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'transactionInterceptor' of type [class org.springframework.transaction.interceptor.TransactionInterceptor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-17 17:41:59.461 INFO 20016 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.config.internalTransactionAdvisor' of type [class org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-17 17:41:59.992 INFO 20016 --- [ main] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: 8090
2016-03-17 17:42:00.261 INFO 20016 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2016-03-17 17:42:00.263 INFO 20016 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/7.0.56
2016-03-17 17:42:00.420 INFO 20016 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2016-03-17 17:42:00.420 INFO 20016 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 5574 ms
2016-03-17 17:42:01.119 INFO 20016 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2016-03-17 17:42:01.124 INFO 20016 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-03-17 17:42:01.519 INFO 20016 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2016-03-17 17:42:01.534 INFO 20016 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2016-03-17 17:42:01.648 INFO 20016 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {4.3.7.Final}
2016-03-17 17:42:01.651 INFO 20016 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2016-03-17 17:42:01.653 INFO 20016 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2016-03-17 17:42:01.991 INFO 20016 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2016-03-17 17:42:02.076 INFO 20016 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2016-03-17 17:42:02.155 INFO 20016 --- [ main] o.h.h.i.ast.ASTQueryTranslatorFactory : HHH000397: Using ASTQueryTranslatorFactory
2016-03-17 17:42:02.534 INFO 20016 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-03-17 17:42:02.986 INFO 20016 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/bibi/commentIncrTop],methods=[],params=[],headers=[],consumes=[],produces=[application/json;charset=UTF-8],custom=[]}" onto public java.lang.String com.hello.bibi.controller.BibiController.commentIncrTop(javax.servlet.http.HttpServletRequest,int,int)
2016-03-17 17:42:02.986 INFO 20016 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/bibi/priceReduce],methods=[],params=[],headers=[],consumes=[],produces=[application/json;charset=UTF-8],custom=[]}" onto public java.lang.String com.hello.bibi.controller.BibiController.priceReduce(javax.servlet.http.HttpServletRequest,int,int)
2016-03-17 17:42:02.987 INFO 20016 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/bibi/categoryTree],methods=[],params=[],headers=[],consumes=[],produces=[application/json;charset=UTF-8],custom=[]}" onto public java.lang.String com.hello.bibi.controller.BibiController.categoryTree(javax.servlet.http.HttpServletRequest)
2016-03-17 17:42:02.992 INFO 20016 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/taomi/collect],methods=[GET],params=[],headers=[],consumes=[],produces=[application/json;charset=UTF-8],custom=[]}" onto public void com.hello.bibi.controller.CollectController.itemInfo(java.lang.String,java.lang.String,java.lang.String)
2016-03-17 17:42:02.994 INFO 20016 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[//testpage],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.hello.bibi.controller.HelloWorldController.helloWorld()
2016-03-17 17:42:02.994 INFO 20016 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[//test],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.hello.bibi.controller.HelloWorldController.helloWorld2(java.lang.String,int)
2016-03-17 17:42:02.994 INFO 20016 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[//test2/{id}],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.hello.bibi.controller.HelloWorldController.test2(long)
2016-03-17 17:42:02.994 INFO 20016 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[//test3/{str}],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.hello.bibi.controller.HelloWorldController.test3(java.lang.String)
2016-03-17 17:42:02.994 INFO 20016 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[//test4],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.hello.bibi.controller.HelloWorldController.test4(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2016-03-17 17:42:02.995 INFO 20016 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[//test5/{id}/vv/{str}],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.hello.bibi.controller.HelloWorldController.test5(java.lang.String,java.lang.String)
2016-03-17 17:42:02.995 INFO 20016 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[//user],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.hello.bibi.controller.HelloWorldController.user()
2016-03-17 17:42:02.995 INFO 20016 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/user/test],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.hello.bibi.controller.UserController.isNameExist(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2016-03-17 17:42:02.998 INFO 20016 --- [ main] 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)
2016-03-17 17:42:02.998 INFO 20016 --- [ main] 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)
2016-03-17 17:42:03.043 INFO 20016 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-03-17 17:42:03.043 INFO 20016 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-03-17 17:42:03.526 INFO 20016 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-03-17 17:42:03.528 INFO 20016 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource4bibi' has been autodetected for JMX exposure
2016-03-17 17:42:03.532 INFO 20016 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource4bibi': registering with JMX server as MBean [com.jolbox.bonecp:name=dataSource4bibi,type=BoneCPDataSource]
2016-03-17 17:42:03.729 INFO 20016 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8090/http
2016-03-17 17:42:03.731 INFO 20016 --- [ main] com.hello.bibi.App : Started App in 10.01 seconds (JVM running for 10.872)
2016-03-17 17:42:04.217 INFO 20016 --- [nio-8090-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2016-03-17 17:42:04.217 INFO 20016 --- [nio-8090-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2016-03-17 17:42:04.243 INFO 20016 --- [nio-8090-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 26 ms
2016-03-17 20:01:59.081 INFO 20016 --- [ Thread-2] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#5cf0ac6e: startup date [Thu Mar 17 17:41:54 CST 2016]; root of context hierarchy
2016-03-17 20:01:59.085 INFO 20016 --- [ Thread-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2016-03-17 20:01:59.090 INFO 20016 --- [ Thread-2] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2016-03-17 20:01:59.092 INFO 20016 --- [ Thread-2] com.jolbox.bonecp.BoneCP : Shutting down connection pool...
2016-03-17 20:01:59.101 INFO 20016 --- [ Thread-2] com.jolbox.bonecp.BoneCP : Connection pool has been shutdown.
App.java
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
#Configuration
#ComponentScan
#EnableAutoConfiguration
public class App {
public static void main( String[] args ) {
SpringApplication.run(App.class);
}
}
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.hello.bibi</groupId>
<artifactId>bibi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>bibi</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.9.RELEASE</version>
</parent>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mybatis.version>3.2.2</mybatis.version>
<mybatisspring.version>1.2.0</mybatisspring.version>
<app.mainClass>com.hello.bibi.App</app.mainClass>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatisspring.version}</version>
</dependency>
<dependency>
<groupId>com.jolbox</groupId>
<artifactId>bonecp</artifactId>
<version>0.8.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>${app.mainClass}</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run your application as follows instead:
nohup java -jar xxx.jar > output.log 2>&1&
From Wikipedia:
nohup is a POSIX command to ignore the HUP (hangup) signal. The HUP signal is, by convention, the way a terminal warns dependent processes of logout. Output that would normally go to the terminal goes to a file called nohup.out if it has not already been redirected.
From the Linux man pages:
nohup - run a command immune to hangups, with output to a non-tty
Furthermore, if you are only adding the web server to keep your application alive and do not actually use it, consider using a CountDownLatch instead:
#Bean
public CountDownLatch closeLatch() {
return new CountDownLatch(1);
}
public static void main(String... args) throws InterruptedException {
ApplicationContext ctx = SpringApplication.run(MyApp.class, args);
final CountDownLatch closeLatch = ctx.getBean(CountDownLatch.class);
Runtime.getRuntime().addShutdownHook(new Thread() {
#Override
public void run() {
closeLatch.countDown();
}
});
closeLatch.await();
}
Now to stop your application, you can look up the process ID and issue a kill command from the console:
kill <PID>