Spring boot(data) heisenbug with detecting database driver - java

During developing Spring boot REST endpoints encounter strange(heisenbug) behavior of my application. Also might be relevant that I made separate modules for each endpoint project. In details it can run one time but fail after rerun, might run one endpoint but not another and vice versa.
Description:
Cannot determine embedded database driver class for database type NONE
Action:
If you want an embedded database please put a supported one on the
classpath. If you have database settings to be loaded from a
particular profile you may need to active it (no profiles are
currently active).
My gradle config:
buildscript {
ext {
springBootVersion = '1.5.6.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
// compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-hateoas')
compile('org.springframework.boot:spring-boot-starter-web')
runtime('mysql:mysql-connector-java')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
and application.propperties
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true
spring.datasource.url = jdbc:mysql://localhost:3306/customers?useSSL=false
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username = root
spring.datasource.password = root
server.port=8090
My repo:
#RepositoryRestResource(collectionResourceRel = "customers", path = "customers ")
public interface CustomerRepository extends PagingAndSortingRepository<Customer, Long> {
List<Customer> findByName(#Param("name") String name);
#Override
#RestResource(exported = false)
void delete(Long id);
#Override
#RestResource(exported = false)
void delete(Customer entity);
}
And my main:
#SpringBootApplication
public class CustomerApplication {
public static void main(String[] args) {
SpringApplication.run(CustomerApplication.class, args);
}
}
Error stack trace:
2017-08-25 11:51:03.316 INFO 14116 --- [ main] c.b.e.s.p.product.ProductApplication : Starting ProductApplication on PF0MQ6SH with PID 14116 (C:\Users\yevhen.shymko\IdeaProjects\shop\product\out\production\classes started by yevhen.shymko in C:\Users\yevhen.shymko\IdeaProjects\shop)
2017-08-25 11:51:03.321 INFO 14116 --- [ main] c.b.e.s.p.product.ProductApplication : No active profile set, falling back to default profiles: default
2017-08-25 11:51:03.420 INFO 14116 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#15bb6bea: startup date [Fri Aug 25 11:51:03 CEST 2017]; root of context hierarchy
2017-08-25 11:51:05.007 INFO 14116 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'httpRequestHandlerAdapter' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]]
2017-08-25 11:51:05.068 INFO 14116 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'managementServletContext' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.actuate.autoconfigure.EndpointWebMvcHypermediaManagementContextConfiguration; factoryMethodName=managementServletContext; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/actuate/autoconfigure/EndpointWebMvcHypermediaManagementContextConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration; factoryMethodName=managementServletContext; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.class]]
2017-08-25 11:51:05.696 INFO 14116 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$e6633d19] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-08-25 11:51:06.165 INFO 14116 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-08-25 11:51:06.179 INFO 14116 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2017-08-25 11:51:06.180 INFO 14116 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.16
2017-08-25 11:51:06.600 INFO 14116 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-08-25 11:51:06.600 INFO 14116 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3184 ms
2017-08-25 11:51:07.259 INFO 14116 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-08-25 11:51:07.272 INFO 14116 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'metricsFilter' to: [/*]
2017-08-25 11:51:07.273 INFO 14116 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-08-25 11:51:07.273 INFO 14116 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-08-25 11:51:07.273 INFO 14116 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-08-25 11:51:07.274 INFO 14116 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2017-08-25 11:51:07.274 INFO 14116 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'webRequestLoggingFilter' to: [/*]
2017-08-25 11:51:07.274 INFO 14116 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'applicationContextIdFilter' to: [/*]
2017-08-25 11:51:07.445 WARN 14116 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
2017-08-25 11:51:07.449 INFO 14116 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2017-08-25 11:51:07.501 INFO 14116 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-08-25 11:51:07.519 ERROR 14116 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Cannot determine embedded database driver class for database type NONE
Action:
If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
Process finished with exit code 1

The solution is quite strange - to refresh gradle project manually after some changes.

Related

Spring Boot HIbernate Issue: Error executing DDL via JDBC Statement with ddl-auto=create-drop

I am a novice with Spring and Hibernate and have tried everything I could find to fix this with no luck. Any assistance would be greatly appreciated. I am currently following a sample project in a book, and am getting an error that says "GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement." I am using a MariaDB database, and my hibernate dialect is org.hibernate.dialect.MySQL5InnoDBDialect.
The query causing this issue is
alter table car drop foreign key FK2mqqwvxtowv4vddvtsmvtiqa2;
If I try to run this query directly in the database it works fine. I have the ddl-auto property set to create-drop, so maybe it is trying to execute this query when the car table has been dropped and is not there? I'm not sure why it would do that or how to turn off this behavior if that is the problem.
If I change ddl-auto to validate or update, the application fails to run at all. If I change it to create, it works fine and I get no errors.
With create-drop, the application does connect to the database and all my tables are created. The tables are still defined as they should be, but the error remains.
Console output:
2018-07-25 16:56:24.229 INFO 12414 --- [ restartedMain] c.p.cardatabase.CardatabaseApplication : Starting CardatabaseApplication on Northstar-2.local with PID 12414 2018-07-25 16:56:24.230 INFO 12414 --- [ restartedMain] c.p.cardatabase.CardatabaseApplication : No active profile set, falling back to default profiles: default
2018-07-25 16:56:24.278 INFO 12414 --- [ restartedMain] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#42e3f007: startup date [Wed Jul 25 16:56:24 AKDT 2018]; root of context hierarchy
2018-07-25 16:56:25.134 INFO 12414 --- [ restartedMain] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'httpRequestHandlerAdapter' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]]
2018-07-25 16:56:25.535 INFO 12414 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$e5303d26] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-07-25 16:56:25.850 INFO 12414 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2018-07-25 16:56:25.875 INFO 12414 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-07-25 16:56:25.875 INFO 12414 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.29
2018-07-25 16:56:25.883 INFO 12414 --- [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: [/Users/tatiana/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]
2018-07-25 16:56:26.025 INFO 12414 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-07-25 16:56:26.025 INFO 12414 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1750 ms
2018-07-25 16:56:26.155 INFO 12414 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-07-25 16:56:26.156 INFO 12414 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-07-25 16:56:26.156 INFO 12414 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-07-25 16:56:26.156 INFO 12414 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-07-25 16:56:26.156 INFO 12414 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2018-07-25 16:56:26.156 INFO 12414 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2018-07-25 16:56:26.288 INFO 12414 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2018-07-25 16:56:26.354 INFO 12414 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2018-07-25 16:56:26.385 INFO 12414 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2018-07-25 16:56:26.401 INFO 12414 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2018-07-25 16:56:26.467 INFO 12414 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate Core {5.2.16.Final}
2018-07-25 16:56:26.469 INFO 12414 --- [ restartedMain] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2018-07-25 16:56:26.504 INFO 12414 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2018-07-25 16:56:26.602 INFO 12414 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
2018-07-25 16:56:27.062 WARN 12414 --- [ restartedMain] o.h.t.s.i.ExceptionHandlerLoggedImpl : GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlString(SchemaDropperImpl.java:375) [hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlStrings(SchemaDropperImpl.java:359) [hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.tool.schema.internal.SchemaDropperImpl.applyConstraintDropping(SchemaDropperImpl.java:331) [hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.tool.schema.internal.SchemaDropperImpl.dropFromMetadata(SchemaDropperImpl.java:230) [hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.tool.schema.internal.SchemaDropperImpl.performDrop(SchemaDropperImpl.java:154) [hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:126) [hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:112) [hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:144) [hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72) [hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:312) [hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:460) [hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:892) [hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) [spring-orm-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) [spring-orm-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390) [spring-orm-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) [spring-orm-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) [spring-orm-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1761) [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1698) [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:579) [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501) [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1089) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:859) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at com.packt.cardatabase.CardatabaseApplication.main(CardatabaseApplication.java:28) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.0.1.RELEASE.jar:2.0.1.RELEASE]
Caused by: java.sql.SQLSyntaxErrorException: (conn=342) Table 'cardb.car' doesn't exist
at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.get(ExceptionMapper.java:177) ~[mariadb-java-client-2.2.3.jar:na]
at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.getException(ExceptionMapper.java:110) ~[mariadb-java-client-2.2.3.jar:na]
at org.mariadb.jdbc.MariaDbStatement.executeExceptionEpilogue(MariaDbStatement.java:228) ~[mariadb-java-client-2.2.3.jar:na]
at org.mariadb.jdbc.MariaDbStatement.executeInternal(MariaDbStatement.java:334) ~[mariadb-java-client-2.2.3.jar:na]
at org.mariadb.jdbc.MariaDbStatement.execute(MariaDbStatement.java:386) ~[mariadb-java-client-2.2.3.jar:na]
at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95) ~[HikariCP-2.7.8.jar:na]
at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java) ~[HikariCP-2.7.8.jar:na]
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
... 40 common frames omitted
Caused by: java.sql.SQLException: Table 'cardb.car' doesn't exist
Query is: alter table car drop foreign key FK2mqqwvxtowv4vddvtsmvtiqa2
at org.mariadb.jdbc.internal.util.LogQueryTool.exceptionWithQuery(LogQueryTool.java:119) ~[mariadb-java-client-2.2.3.jar:na]
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executeQuery(AbstractQueryProtocol.java:199) ~[mariadb-java-client-2.2.3.jar:na]
at org.mariadb.jdbc.MariaDbStatement.executeInternal(MariaDbStatement.java:328) ~[mariadb-java-client-2.2.3.jar:na]
... 44 common frames omitted
[ . . . Mapping details here, omitted]
2018-07-25 16:56:27.118 INFO 12414 --- [ restartedMain] o.h.t.schema.internal.SchemaCreatorImpl : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl#23352c6f'
2018-07-25 16:56:27.121 INFO 12414 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-07-25 16:56:28.047 INFO 12414 --- [ restartedMain] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: org.springframework.security.web.util.matcher.AnyRequestMatcher#1, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#7ec73b7e, org.springframework.security.web.context.SecurityContextPersistenceFilter#6f233313, org.springframework.security.web.header.HeaderWriterFilter#1e641fa3, org.springframework.security.web.csrf.CsrfFilter#7c5a0312, org.springframework.security.web.authentication.logout.LogoutFilter#176619be, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#26add7c1, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter#4030f929, org.springframework.security.web.authentication.www.BasicAuthenticationFilter#2ea06fad, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#6ce594ae, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#6159e3c1, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#51157300, org.springframework.security.web.session.SessionManagementFilter#5be9c504, org.springframework.security.web.access.ExceptionTranslationFilter#4506e3d3, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#1f44843c]
org.springframework.http.HttpEntity<org.springframework.hateoas.ResourceSupport> org.springframework.data.rest.webmvc.ProfileController.listAllFormsOfMetadata()
2018-07-25 16:56:28.632 INFO 12414 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2018-07-25 16:56:28.668 INFO 12414 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-07-25 16:56:28.670 INFO 12414 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure
2018-07-25 16:56:28.676 INFO 12414 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2018-07-25 16:56:28.712 INFO 12414 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-07-25 16:56:28.715 INFO 12414 --- [ restartedMain] c.p.cardatabase.CardatabaseApplication : Started CardatabaseApplication in 4.726 seconds (JVM running for 5.165)
Here is the code on my repo:
https://github.com/Kallaste/spring_login_server_example_so
I wouldn’t worry about it if your application still runs. Hibernate throws a lot of ‘informative’ errors on startup. It just tries to figure out what it has to do to get the database in a state where your application can run.
If the app runs fine if you use create-drop or just create, then try running it with create just once so everything is generated and then change it to validate so the next time it only validates your database schema.
In a production environment you would generally not let Hibernate update the database schema by itself but manually apply changes and migrate data anyway, unless you’re very sure the changes would be applied correctly.
You should use create the first time you run your application, but the next runs have to have update.
When you use create you create the schema and destroy the previous data.
And create-drop destroy the schema in the end of the session. update only update you schema.
update should still be valid. If tables don't exist, it will behave as create.
Are you sure your DB and DBDialect match?
Add #Table annotation like below
#Table(name="car") in car entity. Always give name to table .
Note:
1) When ddl-auto=create-drop and if you don't have #Table(name="car") always you will get this exception.
2) When ddl-auto=create-drop and if you have #Table(name="car") the first time alone you will get this exception.
So try to change the ddl-auto value to other than create-drop . May be you can use "create" or "update"
Hope this helps.
Need to change spring.jpa.hibernate.ddl-auto =update instead of create-drop in application.properties file. Because It is dropping the database at the start of the application and so it won't find the required events table to alter anything.
The problem is because you don't have permissions on the database user.

Spring Boot app crashes by unknown reasons

I packed my Spring Boot application into jar like others same applications that works correctly. It's almost same apps. But this app failed with errors:
2018-01-28 23:43:57.661 DEBUG 14109 --- [ main] o.s.w.c.s.StandardServletEnvironment : Adding PropertySource 'servletConfigInitParams' with lowest search precedence
2018-01-28 23:43:57.670 DEBUG 14109 --- [ main] o.s.w.c.s.StandardServletEnvironment : Adding PropertySource 'servletContextInitParams' with lowest search precedence
2018-01-28 23:43:57.671 DEBUG 14109 --- [ main] o.s.w.c.s.StandardServletEnvironment : Adding PropertySource 'systemProperties' with lowest search precedence
2018-01-28 23:43:57.672 DEBUG 14109 --- [ main] o.s.w.c.s.StandardServletEnvironment : Adding PropertySource 'systemEnvironment' with lowest search precedence
2018-01-28 23:43:57.673 DEBUG 14109 --- [ main] o.s.w.c.s.StandardServletEnvironment : Initialized StandardServletEnvironment with PropertySources [StubPropertySource {name='servletConfigInitParams'}, StubPropertySource {name='servletContextInitParams'}, MapPropertySource {name='systemProperties'}, SystemEnvironmentPropertySource {name='systemEnvironment'}]
2018-01-28 23:43:57.780 INFO 14109 --- [ main] com.contedevel.virto.Application : Starting Application on CONTEDEVEL with PID 14109 (/home/ghostman/Projects/Virto/out/virto.jar started by ghostman in /home/ghostman/Projects/Virto/out)
2018-01-28 23:43:57.781 INFO 14109 --- [ main] com.contedevel.virto.Application : No active profile set, falling back to default profiles: default
2018-01-28 23:43:57.925 INFO 14109 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#928763c: startup date [Sun Jan 28 23:43:57 MSK 2018]; root of context hierarchy
2018-01-28 23:43:59.766 INFO 14109 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'httpRequestHandlerAdapter' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]]
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1 (file:/home/ghostman/Projects/Virto/out/spring-core-4.3.13.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2018-01-28 23:44:00.354 DEBUG 14109 --- [ main] o.s.w.c.s.StandardServletEnvironment : Adding PropertySource 'applicationConfig: [classpath:/application.properties]' with search precedence immediately lower than 'applicationConfigurationProperties'
2018-01-28 23:44:00.355 DEBUG 14109 --- [ main] o.s.w.c.s.StandardServletEnvironment : Removing PropertySource 'applicationConfigurationProperties'
2018-01-28 23:44:00.355 DEBUG 14109 --- [ main] o.s.w.c.s.StandardServletEnvironment : Removing PropertySource 'defaultProperties'
2018-01-28 23:44:00.695 INFO 14109 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$430fc63b] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-01-28 23:44:01.549 INFO 14109 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2018-01-28 23:44:01.574 INFO 14109 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-01-28 23:44:01.576 INFO 14109 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.23
2018-01-28 23:44:01.733 INFO 14109 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-01-28 23:44:01.734 DEBUG 14109 --- [ost-startStop-1] o.s.web.context.ContextLoader : Published root WebApplicationContext as ServletContext attribute with name [org.springframework.web.context.WebApplicationContext.ROOT]
2018-01-28 23:44:01.734 INFO 14109 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3819 ms
2018-01-28 23:44:01.979 INFO 14109 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2018-01-28 23:44:01.988 INFO 14109 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-01-28 23:44:01.989 INFO 14109 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestLoggingFilter' to: [/*]
2018-01-28 23:44:02.062 DEBUG 14109 --- [ost-startStop-1] o.s.w.f.CommonsRequestLoggingFilter : Initializing filter 'requestLoggingFilter'
2018-01-28 23:44:02.069 DEBUG 14109 --- [ost-startStop-1] o.s.w.f.CommonsRequestLoggingFilter : Filter 'requestLoggingFilter' configured successfully
2018-01-28 23:44:02.099 DEBUG 14109 --- [ main] o.s.w.c.s.StandardServletEnvironment : Replacing PropertySource 'servletContextInitParams' with 'servletContextInitParams'
2018-01-28 23:44:02.838 WARN 14109 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Unable to resolve persistence unit root URL
2018-01-28 23:44:02.860 INFO 14109 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2018-01-28 23:44:02.919 INFO 14109 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-01-28 23:44:02.936 ERROR 14109 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Unable to resolve persistence unit root URL
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1080) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at com.contedevel.virto.Application.main(Application.java:17) [virto.jar:na]
Caused by: javax.persistence.PersistenceException: Unable to resolve persistence unit root URL
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:605) ~[spring-orm-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.preparePersistenceUnitInfos(DefaultPersistenceUnitManager.java:445) ~[spring-orm-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.afterPropertiesSet(DefaultPersistenceUnitManager.java:426) ~[spring-orm-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:325) ~[spring-orm-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
... 16 common frames omitted
Caused by: java.io.FileNotFoundException: class path resource [] cannot be resolved to URL because it does not exist
at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:187) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:601) ~[spring-orm-4.3.13.RELEASE.jar:4.3.13.RELEASE]
... 21 common frames omitted
I can't get where is my error. I used java --add-modules java.xml.bind -jar virto.jar command to run app. Jar contains MANIFEST.MF and .properties files like in other my apps that works perfectly.
Has someone any ideas where should I search an error? Below my build.gradle:
buildscript {
ext {
springBootVersion = '1.5.9.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
group = 'com.contedevel'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.9
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.json:json')
runtime('org.postgresql:postgresql')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
My MANIFEST.MF:
Manifest-Version: 1.0
Class-Path: jackson-core-2.8.10.jar jackson-annotations-2.8.0.jar logb
ack-classic-1.1.11.jar tomcat-annotations-api-8.5.23.jar logback-core
-1.1.11.jar slf4j-api-1.7.25.jar spring-data-commons-1.13.9.RELEASE.j
ar antlr-2.7.7.jar spring-data-rest-core-2.6.9.RELEASE.jar spring-hat
eoas-0.23.0.RELEASE.jar spring-boot-starter-logging-1.5.9.RELEASE.jar
hibernate-validator-5.3.6.Final.jar spring-boot-starter-web-1.5.9.RE
LEASE.jar snakeyaml-1.17.jar hibernate-core-5.0.12.Final.jar jcl-over
-slf4j-1.7.25.jar spring-boot-autoconfigure-1.5.9.RELEASE.jar dom4j-1
.6.1.jar spring-beans-4.3.13.RELEASE.jar spring-core-4.3.13.RELEASE.j
ar jackson-databind-2.8.10.jar tomcat-embed-el-8.5.23.jar spring-boot
-starter-data-jpa-1.5.9.RELEASE.jar spring-web-4.3.13.RELEASE.jar evo
-inflector-1.2.2.jar hibernate-commons-annotations-5.0.1.Final.jar js
on-20140107.jar spring-aop-4.3.13.RELEASE.jar log4j-over-slf4j-1.7.25
.jar tomcat-jdbc-8.5.23.jar hibernate-jpa-2.1-api-1.0.0.Final.jar spr
ing-data-rest-webmvc-2.6.9.RELEASE.jar jul-to-slf4j-1.7.25.jar spring
-boot-starter-1.5.9.RELEASE.jar spring-expression-4.3.13.RELEASE.jar
spring-boot-1.5.9.RELEASE.jar spring-orm-4.3.13.RELEASE.jar classmate
-1.3.4.jar hibernate-entitymanager-5.0.12.Final.jar tomcat-juli-8.5.2
3.jar spring-boot-starter-aop-1.5.9.RELEASE.jar spring-data-jpa-1.11.
9.RELEASE.jar spring-boot-starter-tomcat-1.5.9.RELEASE.jar validation
-api-1.1.0.Final.jar spring-tx-4.3.13.RELEASE.jar spring-aspects-4.3.
13.RELEASE.jar tomcat-embed-core-8.5.23.jar jandex-2.0.0.Final.jar jb
oss-logging-3.3.1.Final.jar javax.transaction-api-1.2.jar spring-boot
-starter-jdbc-1.5.9.RELEASE.jar spring-jdbc-4.3.13.RELEASE.jar spring
-context-4.3.13.RELEASE.jar aspectjweaver-1.8.13.jar postgresql-9.4.1
212.jre7.jar spring-webmvc-4.3.13.RELEASE.jar spring-boot-starter-dat
a-rest-1.5.9.RELEASE.jar javassist-3.21.0-GA.jar spring-plugin-core-1
.2.0.RELEASE.jar tomcat-embed-websocket-8.5.23.jar
Main-Class: com.contedevel.virto.Application
application.properties:
spring.datasource.url=jdbc:postgresql://localhost:5432/virto
spring.datasource.username=virto_user
spring.datasource.password=****
#spring.datasource.driver-class-name=xxx
spring.jpa.hibernate.ddl-auto=create-drop
#show sql statement
logging.level.org.hibernate.SQL=error
#show sql values
logging.level.org.hibernate.type.descriptor.sql=trace
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR
logging.file=${user.home}/Logs/virto.log
#server
server.port = 8080
Looks like this is a bug in the spring project. You are not the first to encounter it. There are a few places it seems to be reported as a bug:
github.com/spring-projects/spring-boot/issues/6635
github.com/spring-projects/spring-boot/issues/6314
stackoverflow.com/questions/38686708/spring-boot-1-4-class-path-resource-cannot-be-resolved-to-url-because-it-do
Since it's a bug, probably not worth the time to understand it exactly, just use one of the listed solutions or workarounds.
if you are running it in Linux or EC2 AWS Linux use nohup command to run the jar filr as below.
nohup java -jar /web/server.jar > /var/log/yourservice.log 2>&1

Why doesn't SpringBootApplication register my controller as a handler?

This is first time i am working with spring and I am kind a stuck. Here is what i have so far
My Application that runs on embedded tomcat
package com.company.project.application;
#SpringBootApplication
public class SampleApplication {
private static Log logger = LogFactory.getLog(SampleApplication.class);
#Bean
protected ServletContextListener listener(){
return new ServletContextListener() {
public void contextInitialized(ServletContextEvent servletContextEvent) {
logger.info("ServletContext initialized ...");
}
public void contextDestroyed(ServletContextEvent servletContextEvent) {
logger.info("ServletContext destroyed ... ");
}
};
}
public static void main (String[] args){
SpringApplication.run(SampleApplication.class, args);
}
}
Controller
package com.company.project.controller;
#Controller
public class PaymentController {
#RequestMapping("/")
#ResponseBody
public String helloWorld(){
return "hello";
}
}
I am running this application using the SampleApplicaiton.main. I can see the logs etc in console. When i try to access http://localhost:8080/ it gives me 404. When i try http://localhost:8080/sampleapplication or http://localhost:8080/SampleApplication/ i get the same message.
What i am missing here ?
SpringBoot Logs
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.3.3.RELEASE)
2016-04-21 14:00:54.794 INFO 65461 --- [ main] c.w.p.application.SampleApplication : Starting SampleApplication on WGs-MacBook-Pro.local with PID 65461 (/Users/username/repos/Sample/target/classes started by username in /Users/username/repos/sample)
2016-04-21 14:00:54.799 INFO 65461 --- [ main] c.w.p.application.SampleApplication : No active profile set, falling back to default profiles: default
2016-04-21 14:00:54.892 INFO 65461 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#1f021e6c: startup date [Thu Apr 21 14:00:54 EDT 2016]; root of context hierarchy
2016-04-21 14:00:55.794 INFO 65461 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'beanNameViewResolver' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; 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-04-21 14:00:56.411 INFO 65461 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-04-21 14:00:56.431 INFO 65461 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2016-04-21 14:00:56.433 INFO 65461 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.32
2016-04-21 14:00:56.569 INFO 65461 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2016-04-21 14:00:56.569 INFO 65461 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1697 ms
2016-04-21 14:00:56.838 INFO 65461 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2016-04-21 14:00:56.846 INFO 65461 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-04-21 14:00:56.847 INFO 65461 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-04-21 14:00:56.847 INFO 65461 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-04-21 14:00:56.847 INFO 65461 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2016-04-21 14:00:56.879 INFO 65461 --- [ost-startStop-1] c.w.p.application.SampleApplication : ServletContext initialized ...
2016-04-21 14:00:57.297 INFO 65461 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#1f021e6c: startup date [Thu Apr 21 14:00:54 EDT 2016]; root of context hierarchy
2016-04-21 14:00:57.391 INFO 65461 --- [ 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-04-21 14:00:57.392 INFO 65461 --- [ 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-04-21 14:00:57.418 INFO 65461 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-04-21 14:00:57.419 INFO 65461 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-04-21 14:00:57.467 INFO 65461 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-04-21 14:00:57.584 INFO 65461 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-04-21 14:00:57.680 INFO 65461 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-04-21 14:00:57.686 INFO 65461 --- [ main] c.w.p.application.SampleApplication : Started SampleApplication in 3.998 seconds (JVM running for 4.629)
2016-04-21 14:04:49.523 INFO 65461 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2016-04-21 14:04:49.524 INFO 65461 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2016-04-21 14:04:49.542 INFO 65461 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 18 ms
According to the documentation
Many Spring Boot developers always have their main class annotated
with #Configuration, #EnableAutoConfiguration and #ComponentScan.
Since these annotations are so frequently used together (especially if
you follow the best practices above), Spring Boot provides a
convenient #SpringBootApplication alternative.
The default attributes for #ComponentScan are to search only the package of the annotated class.
If specific packages are not defined, scanning will occur from the
package of the class that declares this annotation.
In your case, that is SampleApplication, which is in a different package than PaymentController. PaymentController therefore won't be included as a bean, nor a handler.
Either move them to the same package or add an explicit #ComponentScan to also scan for
package com.company.project.controller;
Alternatively, #SpringBootApplication also has a scanBasePackages attribute you can use.

How to fix javax.xml.ws.WebServiceException: java.lang.NullPointerException?

I'm running me Spring Boot application (mvn:spring-boot:run) and get next stack trace:
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.3.2.RELEASE)
2016-02-10 09:57:31.350 INFO 8868 --- [ main] com.comp.config.Application : Starting Application on SOFT12 with PID 8868 (C:\Users\Maya\git\app-services\target\classes started by Maya in C:\Users\Maya\git\app-services)
2016-02-10 09:57:31.356 INFO 8868 --- [ main] com.comp.config.Application : No active profile set, falling back to default profiles: default
2016-02-10 09:57:31.429 INFO 8868 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#7dd7f653: startup date [Wed Feb 10 09:57:31 MSK 2016]; root of context hierarchy
2016-02-10 09:57:33.174 INFO 8868 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'beanNameViewResolver' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; 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-02-10 09:57:35.126 INFO 8868 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-02-10 09:57:35.151 INFO 8868 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2016-02-10 09:57:35.153 INFO 8868 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.30
2016-02-10 09:57:35.296 INFO 8868 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2016-02-10 09:57:35.296 INFO 8868 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3871 ms
2016-02-10 09:57:36.401 INFO 8868 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'CXFServlet' to [/APPservice/*]
2016-02-10 09:57:36.408 INFO 8868 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'metricFilter' to: [/*]
2016-02-10 09:57:36.409 INFO 8868 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-02-10 09:57:36.409 INFO 8868 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-02-10 09:57:36.409 INFO 8868 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-02-10 09:57:36.410 INFO 8868 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2016-02-10 09:57:36.410 INFO 8868 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'webRequestLoggingFilter' to: [/*]
2016-02-10 09:57:36.410 INFO 8868 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'applicationContextIdFilter' to: [/*]
2016-02-10 09:57:37.028 INFO 8868 --- [ main] o.a.c.w.s.f.ReflectionServiceFactoryBean : Creating Service {http://new.webservice.namespace}CompServiceForPCO from WSDL: classpath:CompService.wsdl
2016-02-10 09:57:39.665 WARN 8868 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ws' defined in com.comp.config.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.xml.ws.Endpoint]: Factory method 'ws' threw exception; nested exception is javax.xml.ws.WebServiceException: java.lang.NullPointerException
2016-02-10 09:57:39.676 INFO 8868 --- [ main] o.apache.catalina.core.StandardService : Stopping service Tomcat
2016-02-10 09:57:39.891 ERROR 8868 --- [ main] o.s.boot.SpringApplication : Application startup failed
ws method is in Application.class which look like:
package com.comp.config;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import com.comp.pcoserv.CompServiceEndPoindImpl;
import javax.xml.ws.Endpoint;
#Configuration
#EnableAutoConfiguration
public class Application {
public static final String SERVLET_MAPPING_URL_PATH = "/APPservice";
public static final String SERVICE_NAME_URL_PATH = "/ws";
#Autowired
private ApplicationContext applicationContext;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
#Bean
public ServletRegistrationBean dispatcherServlet() {
return new ServletRegistrationBean(new CXFServlet(), SERVLET_MAPPING_URL_PATH + "/*");
}
#Bean(name = Bus.DEFAULT_BUS_ID)
/* <bean id="cxf" class="org.apache.cxf.bus.spring.SpringBus">*/
public SpringBus springBus() {
return new SpringBus();
}
#Bean
/* <jaxws:endpoint id="app" implementor="com.dlizarra.app.ws.AppImpl" address="/app">*/
public Endpoint ws() {
//Bus bus = (Bus) applicationContext.getBean(Bus.DEFAULT_BUS_ID);
Object implementor = new CompServiceEndPoindImpl();
EndpointImpl endpoint = new EndpointImpl(springBus(), implementor);
endpoint.publish(SERVICE_NAME_URL_PATH);
endpoint.setWsdlLocation("CompService.wsdl");
/*endpoint.getServer().getEndpoint().getInInterceptors().add(new LoggingInInterceptor());
endpoint.getServer().getEndpoint().getOutInterceptors().add(new LoggingOutInterceptor());*/
return endpoint;
}
}
I searched through the entire Internet to find the solution but without any success. Could you help me to fix this exception?
The full stack trace is here: full stack trace
This error can happen when the object that your service return doesn't have an empty constructor.
Just make sure that all your dto are empty constructor.
Issue is with Instatiation of ENDPOINT in method ws(). So after this line
EndpointImpl endpoint = new EndpointImpl(springBus(), implementor);
And calling publish on it resulted in NullPointerException
Error trail:-
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.xml.ws.Endpoint]: Factory method 'ws' threw exception; nested exception is javax.xml.ws.WebServiceException: java.lang.NullPointerException
Caused by: javax.xml.ws.WebServiceException: java.lang.NullPointerException
at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:375) ~[cxf-rt-frontend-jaxws-3.1.5.jar:3.1.5]
at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:255) ~[cxf-rt-frontend-jaxws-3.1.5.jar:3.1.5]
Extended error trail :-
Caused by: java.lang.NullPointerException: null
at org.apache.cxf.common.util.ASMHelper.getClassCode(ASMHelper.java:212) ~[cxf-core-3.1.5.jar:3.1.5]
at org.apache.cxf.jaxws.WrapperClassGenerator.generateMessagePart(WrapperClassGenerator.java:310) ~[cxf-rt-frontend-jaxws-3.1.5.jar:3.1.5]
at org.apache.cxf.jaxws.WrapperClassGenerator.createWrapperClass(WrapperClassGenerator.java:224) ~[cxf-rt-frontend-jaxws-3.1.5.jar:3.1.5]
at org.apache.cxf.jaxws.WrapperClassGenerator.generate(WrapperClassGenerator.java:132) ~[cxf-rt-frontend-jaxws-3.1.5.jar:3.1.5]
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.generatedWrapperBeanClass(JaxWsServiceFactoryBean.java:675) ~[cxf-rt-frontend-jaxws-3.1.5.jar:3.1.5]
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.getExtraClass(JaxWsServiceFactoryBean.java:645) ~[cxf-rt-frontend-jaxws-3.1.5.jar:3.1.5]
at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.buildServiceFromWSDL(ReflectionServiceFactoryBean.java:417) ~[cxf-rt-wsdl-3.1.5.jar:3.1.5]
at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:525) ~[cxf-rt-wsdl-3.1.5.jar:3.1.5]
at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:261) ~[cxf-rt-wsdl-3.1.5.jar:3.1.5]
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:199) ~[cxf-rt-frontend-jaxws-3.1.5.jar:3.1.5]
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:102) ~[cxf-rt-frontend-simple-3.1.5.jar:3.1.5]
at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:168) ~[cxf-rt-frontend-simple-3.1.5.jar:3.1.5]
at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:211) ~[cxf-rt-frontend-jaxws-3.1.5.jar:3.1.5]
at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:460) ~[cxf-rt-frontend-jaxws-3.1.5.jar:3.1.5]
at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:338) ~[cxf-rt-frontend-jaxws-3.1.5.jar:3.1.5]
... 37 common frames omitted
org.apache.cxf.common.util.ASMHelper:-
public static String getClassCode(Class<?> cl) {
if (cl == Void.TYPE) {
return "V";
}
if (cl.isPrimitive()) {
In my case the problem was in annotation in ServiceInterface class: need
#SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
instead of
#SOAPBinding(parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)
for somу methods.

Creating a RESTful web service with Spring Boot

I am learning RESTful web services using Spring boot. I am trying to create a web service that fetches address of a particular client.However when I try running the service i keep getting the following error:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing
this as a fallback.
Sun Jan 03 11:20:44 CST 2016 There was an unexpected error (type=Not
Found, status=404). No message available
The URL i am trying to access is
http://localhost:8084/showAddress
Can someone please tell me where am i going wrong. I downloaded a similar project from a friend's github account and it runs perfectly OK.
For the sake of simplicity i tried hard coding the values and created the following code in my controller class:
package com.digitek.controller;
import java.math.BigInteger;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.example.model.Address;
#RestController
public class Controller {
private static BigInteger id;
private static Map<BigInteger, Address> addressMap;
//saves address objects into HashMap
private static void SaveAddress(Address address){
//instantiate hashmap when id is null
if(id == null){
id = BigInteger.ONE;
addressMap = new HashMap<BigInteger,Address>();
}
address.setId(id);
id.add(BigInteger.ONE);
addressMap.put(address.getId(), address);
}
static{
Address a1 = new Address();
a1.setAddress("29 East Judith Ann Drive");
SaveAddress(a1);
Address a2 = new Address();
a1.setAddress("2 East Judith Ann Drive");
SaveAddress(a2);
}
#RequestMapping(value = "/showAddress" ,method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Collection<Address>> showMessage(){
Collection<Address> address = addressMap.values();
return new ResponseEntity<Collection<Address>>(address , HttpStatus.OK);
}
}
Here is my pom.xml file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>AddressService</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>AddressService</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Here is the console log
2016-01-03 11:09:30.359 INFO 6028 --- [ main] com.example.AddressServiceApplication : Starting AddressServiceApplication on Rishit with PID 6028 (started by Rishit Shah in D:\Rishit\Java workspaces\AddressService)
2016-01-03 11:09:30.364 INFO 6028 --- [ main] com.example.AddressServiceApplication : No active profile set, falling back to default profiles: default
2016-01-03 11:09:30.449 INFO 6028 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#33cb5951: startup date [Sun Jan 03 11:09:30 CST 2016]; root of context hierarchy 2016-01-03 11:09:31.655 INFO 6028 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'beanNameViewResolver' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; 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-01-03 11:09:32.792 INFO 6028 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8084 (http)
2016-01-03 11:09:32.814 INFO 6028 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat 2016-01-03 11:09:32.816 INFO 6028 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.30 2016-01-03 11:09:32.965 INFO 6028 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2016-01-03 11:09:32.965 INFO 6028 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2521 ms
2016-01-03 11:09:33.628 INFO 6028
--- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2016-01-03 11:09:33.637 INFO 6028 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-01-03 11:09:33.639 INFO 6028
--- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-01-03 11:09:33.639 INFO 6028 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-01-03 11:09:33.639 INFO 6028
--- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2016-01-03 11:09:34.221 INFO 6028 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#33cb5951: startup date [Sun Jan 03 11:09:30 CST 2016]; root of context hierarchy 2016-01-03 11:09:34.315 INFO 6028 --- [ 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-01-03 11:09:34.317 INFO 6028 --- [ 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-01-03 11:09:34.371 INFO 6028 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-01-03 11:09:34.371 INFO 6028 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2016-01-03 11:09:34.421 INFO 6028 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2016-01-03 11:09:34.588 INFO 6028 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-01-03 11:09:34.753 INFO 6028 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8084 (http)
2016-01-03 11:09:34.764 INFO 6028 --- [ main] com.example.AddressServiceApplication : Started AddressServiceApplication in 4.867 seconds (JVM running for 5.705)
2016-01-03 11:10:03.737 INFO 6028 --- [nio-8084-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet' 2016-01-03 11:10:03.737 INFO 6028 --- [nio-8084-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started 2016-01-03 11:10:03.759 INFO 6028 --- [nio-8084-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 22 ms
P.S
I tried running the application on different ports, tried deleting and re creating it, and also tried running a similar application i downloaded from github created by my friend. Each time his application works but mine doesn't. I also made sure each and elements of our pom files match.
Thank you in advance
Make sure that your main class is in a root package above other classes.
When you run a Spring Boot Application, (i.e. a class annotated with #SpringBootApplication), Spring will only scan the classes below your main class package.
com
+- digitek
+- Application.java <--- your main class should be here, above your controller classes
|
+- model
| +- Address.java
+- controller
+- AddressController.java
The problem in your case was that Spring could not find the controller you created, because you placed it in a directory which was not scanned by Spring.
There is a chapter in the docs explaining how to structure your code using spring boot here.

Categories