The bean 'metaDataSourceAdvisor', defined in null, could not be registered - spring-boot

I've updated the Spring Boot version from 2.0.3 to 2.1.1 but I'm getting this:
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'metaDataSourceAdvisor', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
I get the error - the problem is that defined in null is not really a good pointer where to look. I've seen this question but I'd actually prefer to keep disallowing overriding ambiguous beans.
Any ideas?
Log output
2019-01-06 07:33:39.282 INFO 29626 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2019-01-06 07:33:39.282 INFO 29626 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2019-01-06 07:33:39.912 INFO 29626 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-01-06 07:33:39.997 INFO 29626 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 80ms. Found 23 repository interfaces.
2019-01-06 07:33:39.999 WARN 29626 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'metaDataSourceAdvisor' defined in null: Cannot register bean definition [Root bean: class [org.springframework.security.access.intercept.aopalliance.MethodSecurityMetadataSourceAdvisor]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] for bean 'metaDataSourceAdvisor': There is already [Root bean: class [org.springframework.security.access.intercept.aopalliance.MethodSecurityMetadataSourceAdvisor]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] bound.
2019-01-06 07:33:40.008 INFO 29626 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-01-06 07:33:40.010 ERROR 29626 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :

Okay, I found the issue myself: I had #EnableGlobalMethodSecurity twice in my project:
#Configuration
#EnableWebSecurity
#EnableGlobalMethodSecurity(prePostEnabled = true) // <--
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
}
and
#SpringBootApplication
#EnableJpaRepositories(basePackages = {"mz.server.spring.repository"})
#EnableGlobalMethodSecurity(prePostEnabled = true, proxyTargetClass = true) // <--
#EntityScan(basePackages = "mz.server.hibernate.model")
#EnableTransactionManagement
#EnableScheduling
public class Application {
}
So that's a nice new Spring Boot feature I'd say.
Just watch out for unwanted duplicate annotations if you see this kind of error.

Expanding on the accepted answer, as per the release notes for Spring Boot 2.1
Bean overriding has been disabled by default to prevent a bean being accidentally overridden. If you are relying on overriding, you will need to set spring.main.allow-bean-definition-overriding to true.
So if you have used #EnableGlobalMethodSecurity more than once in your codebase and these beans are part of the same component scan then this annotation will attempt to create the metaDataSourceAdvisor bean more than once. This will throw an exception during initialization.
This will also apply to other auto configuration annotations that create beans. Make sure to only use their enabling annotations once.

Check if you have missed adding following annotations (whichever applicable)
#EnableJpaRepositories({"com.base.package"})
#EnableMongoRepositories({"com.base.package"})
This worked for me

I tried all these answers. But I noticed that error terminal says spring.main.allow-bean-definition-overriding=true in your properties. Just do it it worked for me.

Can help "clean" and "build" project in Gradle or Maven.

Related

Why ConditionEvaluationReportLoggingListener never invoked in failed context tests using ApplicationContextRunner?

Expected behavior
As a spring-boot developer
in order to diagnose failed context startup in tests using ApplicationContextRunner
I need ConditionEvaluationReportLoggingListener to print report as documented in
https://docs.spring.io/spring-boot/docs/2.3.6.RELEASE/reference/htmlsingle/#boot-features-test-autoconfig
The runner can also be used to display the ConditionEvaluationReport. The report can be printed at INFO or DEBUG level. The following example shows how to use the ConditionEvaluationReportLoggingListener to print the report in auto-configuration tests.
#Test
public void autoConfigTest {
ConditionEvaluationReportLoggingListener initializer = new ConditionEvaluationReportLoggingListener(
LogLevel.INFO);
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withInitializer(initializer).run((context) -> {
// Do something...
});
}
In order to help me diagnose failures of test (in particular when context fails to be initialized), I need to get a report such as the following to understand whether my #ConditionalOnProperty logic is correct.
#Configuration
#ConditionalOnProperty(value= DynamicCatalogConstants.OPT_IN_PROPERTY)
#EnableConfigurationProperties
public class DynamicCatalogServiceAutoConfiguration {
[...]
20-11-2020 14:47:02.380 [main] DEBUG o.s.b.a.l.ConditionEvaluationReportLoggingListener.logAutoConfigurationReport -
============================
CONDITIONS EVALUATION REPORT
============================
Positive matches:
-----------------
DynamicCatalogServiceAutoConfiguration matched:
- #ConditionalOnProperty (osbcmdb.dynamic-catalog.enabled) matched (OnPropertyCondition)
Negative matches:
-----------------
None
Exclusions:
-----------
None
Unconditional classes:
----------------------
None
I'm using spring-boot 2.3.6.
Observed behavior
The condition report is not invoked when context fails to start
Instead of a condition report, only the following context init exception is displayed
20-11-2020 14:24:10.609 [main] WARN o.s.c.a.AnnotationConfigApplicationContext.refresh - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'dynamicCatalogService' defined in com.orange.oss.osbcmdb.catalog.DynamicCatalogServiceAutoConfigurationTest$SingleServiceDefinitionAnswerAutoConfig: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=dynamicCatalogServiceAutoConfigurationTest.SingleServiceDefinitionAnswerAutoConfig; factoryMethodName=dynamicCatalogService; initMethodName=null; destroyMethodName=(inferred); defined in com.orange.oss.osbcmdb.catalog.DynamicCatalogServiceAutoConfigurationTest$SingleServiceDefinitionAnswerAutoConfig] for bean 'dynamicCatalogService': There is already [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=dynamicCatalogServiceAutoConfiguration; factoryMethodName=dynamicCatalogService; initMethodName=null; destroyMethodName=(inferred); defined in com.orange.oss.osbcmdb.catalog.DynamicCatalogServiceAutoConfiguration] bound.
java.lang.IllegalStateException: Unstarted application context org.springframework.boot.test.context.assertj.AssertableApplicationContext[startupFailure=org.springframework.beans.factory.support.BeanDefinitionOverrideException] failed to start
at org.springframework.boot.test.context.assertj.AssertProviderApplicationContextInvocationHandler.getStartedApplicationContext(AssertProviderApplicationContextInvocationHandler.java:156)
at org.springframework.boot.test.context.assertj.AssertProviderApplicationContextInvocationHandler.invokeApplicationContextMethod(AssertProviderApplicationContextInvocationHandler.java:147)
at org.springframework.boot.test.context.assertj.AssertProviderApplicationContextInvocationHandler.invoke(AssertProviderApplicationContextInvocationHandler.java:85)
at com.sun.proxy.$Proxy20.getBean(Unknown Source)
at com.orange.oss.osbcmdb.catalog.DynamicCatalogServiceAutoConfigurationTest.lambda$dynamicServiceLoadWhenOptInProperty$2(DynamicCatalogServiceAutoConfigurationTest.java:84)
Sample code:
#Test
void dynamicServiceLoadWhenOptInProperty() {
ConditionEvaluationReportLoggingListener initializer = new ConditionEvaluationReportLoggingListener(LogLevel.INFO);
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withInitializer(initializer)
.withConfiguration(AutoConfigurations.of(
SingleServiceDefinitionAnswerAutoConfig.class,
DynamicCatalogServiceAutoConfiguration.class,
MockedMaintenanceInfoFormatterServiceConfig.class
))
.withPropertyValues(DynamicCatalogConstants.OPT_IN_PROPERTY + "=true");
contextRunner.run(context -> {
Catalog catalog = context.getBean(Catalog.class);
assertThat(catalog.getServiceDefinitions()).isNotEmpty();
assertThat(context).hasSingleBean(Catalog.class);
});
}
What I tried
The logging level is properly set to debug.
Stepping into the debugger, it seems that the ConditionEvaluationReportLoggingListener is never invoked for event notifications.
I however managed to manually trigger the condition report printed by invoking it explicitly with the debugger:
Should I submit an issue on the springboot repo ?
The limitation was acknowledged by the spring-boot team in https://github.com/spring-projects/spring-boot/issues/24235
Hopefully a future improvement will fix this problem.

is there any conflict between spring-boot-starter-parent version 2 and spring-security-jwt and spring-security-oauth2

I am trying to fix an issue I am facing with Spring Boot + Java 8 and Hibernate (my original question regard this issue is org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value did not match expected type java.time.LocalDateTime).
Since I read Since 5.2, "the hibernate-java8 module has been merged into hibernate-core and the Java 8 date/time types are now natively supported." from How to persist JSR-310 types with Spring Data JPA?, I tried to update all my Spring Boot dependencies to the most recent.
I mean, my parent pom was before:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/>
</parent>
and I changed to
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/>
</parent>
The purpose to do that was take advantage of "...now natively supported..." as mentioned above assuming it could fix any conflict I could be facing with datetime.
Now I am facing another issue with
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-jwt</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
</dependency>
saying: Project build error: 'dependencies.dependency.version' for org.springframework.security.oauth:spring-security-oauth2:jar is
missing (same for org.springframework.security:spring-security-jwt:jar).
How can I fix that specific issue with org.springframework.security:spring-security-jwt:jar and org.springframework.security.oauth:spring-security-oauth2:jar ?
*** edited, after I change the version as mentioned above, I am getting
:: Spring Boot :: (v1.5.6.RELEASE)
2018-03-26 17:53:10.490 INFO 1161 --- [ restartedMain] br.com.moving.MovingApiApplication : Starting MovingApiApplication on fulls-iMac.home with PID 1161 (/Users/accountname/WSs/ws_servicos_prontos/api-moving/target/classes started by accountname in /Users/accountname/WSs/ws_servicos_prontos/api-moving)
2018-03-26 17:53:10.492 INFO 1161 --- [ restartedMain] br.com.moving.MovingApiApplication : The following profiles are active: ${envspring}
2018-03-26 17:53:10.607 INFO 1161 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#64f45797: startup date [Mon Mar 26 17:53:10 BRT 2018]; root of context hierarchy
2018-03-26 17:53:11.879 INFO 1161 --- [ restartedMain] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'commandLineRunner' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=apiSecurityApplication; factoryMethodName=commandLineRunner; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [br/com/moving/ApiSecurityApplication.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=movingApiApplication; factoryMethodName=commandLineRunner; initMethodName=null; destroyMethodName=(inferred); defined in br.com.moving.MovingApiApplication]
2018-03-26 17:53:12.276 INFO 1161 --- [ 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.web.servlet.config.annotation.DelegatingWebMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.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-03-26 17:53:13.017 INFO 1161 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$501c7c5b] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.096 INFO 1161 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration' of type [org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration$$EnhancerBySpringCGLIB$$e8ca4495] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.110 INFO 1161 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'objectPostProcessor' of type [org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.115 INFO 1161 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler#616c515f' of type [org.springframework.security.oauth2.provider.expression.OAuth2MethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.122 INFO 1161 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration' of type [org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration$$EnhancerBySpringCGLIB$$d9ee747] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.157 INFO 1161 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'methodSecurityMetadataSource' of type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.212 INFO 1161 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'security.oauth2.client-org.springframework.boot.autoconfigure.security.oauth2.OAuth2ClientProperties' of type [org.springframework.boot.autoconfigure.security.oauth2.OAuth2ClientProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.218 INFO 1161 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration' of type [org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration$$EnhancerBySpringCGLIB$$766385b] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.254 INFO 1161 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'resourceServerProperties' of type [org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.831 INFO 1161 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 9000 (http)
2018-03-26 17:53:13.847 INFO 1161 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-03-26 17:53:13.848 INFO 1161 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.16
2018-03-26 17:53:13.972 INFO 1161 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-03-26 17:53:13.972 INFO 1161 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3368 ms
2018-03-26 17:53:14.201 INFO 1161 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-03-26 17:53:14.203 INFO 1161 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2018-03-26 17:53:14.203 INFO 1161 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2018-03-26 17:53:14.263 WARN 1161 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'inMemoryDatabaseShutdownExecutor' defined in class path resource [org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.class]: Unsatisfied dependency expressed through method 'inMemoryDatabaseShutdownExecutor' 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 (the profiles "${envspring}" are currently active).
2018-03-26 17:53:14.270 INFO 1161 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2018-03-26 17:53:14.298 INFO 1161 --- [ restartedMain] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-03-26 17:53:14.303 ERROR 1161 --- [ restartedMain] 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 (the profiles "${envspring}" are currently active).
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.743 s
[INFO] Finished at: 2018-03-26T17:53:14-03:00
[INFO] ------------------------------------------------------------------------
It sounds strange see v1.5.6.RELEASE in logs while I setup 2.0.0.RELEASE for spring-boot-starter-parent
Spring Boot 2.0 migration guide says that
Functionality from the Spring Security OAuth project is being migrated to core Spring Security. Dependency management is no longer provided for that dependency and Spring Boot 2 provides OAuth 2.0 client support via Spring Security 5.
So you should specify jwt and oauth2 dependencies manually.
<spring-security-oauth2.version>2.3.3.RELEASE</spring-security-oauth2.version>
<spring-security-jwt.version>1.0.9.RELEASE</spring-security-jwt.version>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>${spring-security-oauth2.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-jwt</artifactId>
<version>${spring-security-jwt.version}</version>
</dependency>

Unable to hit rest service running with spring boot

I have configured restful webservice and hosted with the help of Spring Boot. But I'm not able to hit the service. And getting Response Status: -1 - Request Failed (Canceled or Timed-Out)
Logs:-
⁃ 2017-10-08 18:33:33.149 INFO 6806 --- [ main] com.mypleaks.PleaksRSApp : Starting PleaksRSApp on 3inmderaj1.local with PID 6806 (/Users/deraj/home/code/leaks-rs/mypleaks-rs/myPleaks-RS/target/classes started by deraj in /Users/deraj/home/code/leaks-rs/mypleaks-rs/myPleaks-RS)
⁃ 2017-10-08 18:33:33.155 INFO 6806 --- [ main] com.mypleaks.PleaksRSApp : No active profile set, falling back to default profiles: default
⁃ 2017-10-08 18:33:33.202 INFO 6806 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#311bf055: startup date [Sun Oct 08 18:33:33 IST 2017]; root of context hierarchy
⁃ 2017-10-08 18:33:33.998 INFO 6806 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'requestContextFilter' 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.jersey.JerseyAutoConfiguration; factoryMethodName=requestContextFilter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.class]] with [Root bean: class [org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=requestContextFilter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
⁃ 2017-10-08 18:33:34.276 INFO 6806 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
⁃ 2017-10-08 18:33:34.372 INFO 6806 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$af71e9e1] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
⁃ 2017-10-08 18:33:34.745 INFO 6806 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
⁃ 2017-10-08 18:33:34.756 INFO 6806 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
⁃ 2017-10-08 18:33:34.756 INFO 6806 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.6
Resource :-
Request:-
Response:-
It seems that you are using the annotations from the javax. package instead of the spring ones.
Try using #RestController on the class level and #RequestMapping on the method level (all other annotations should be from the spring package also):
#RestController
#RequestMapping(path = "/place")
public class PlaceResource{
#RequestMapping(method = RequestMethod.GET, path="/countries")
public Response getCountries(..){..}
}
Sorry Guys, Its was terrible mistake from my side. I had used below code in my application.
public class NotificationEngine implements InitializingBean {
#Override
public void afterPropertiesSet() throws Exception {"Here I was running some stupid endless process, Due to which the tomcat was not getting up completely and because of that Iwas getting this issue."}}
Please check that you have following dependency in your pom.xml, If it is not there please add it and re-run.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

Spring-Boot disable load-on startup rabbitMQ

Why RabbitMQ is triggered or running while building the spring-boot jar.While running the Application.java or pom.xml.
i am able to see the following loggers
2016-07-01 16:40:04.334 INFO 7004 --- [ main] com.rabbit.App : No active profile set, falling back to default profiles: default
2016-07-01 16:40:04.391 INFO 7004 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#1da51a35: startup date [Fri Jul 01 16:40:04 CEST 2016]; root of context hierarchy
2016-07-01 16:40:05.331 INFO 7004 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'rabbitListenerContainerFactory' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=rabbitMqConfiguration; factoryMethodName=rabbitListenerContainerFactory; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/rabbit/messaging/configuration/RabbitMqConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=taskConsumerConfiguration; factoryMethodName=rabbitListenerContainerFactory; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/rabbit/messaging/configuration/TaskConsumerConfiguration.class]]
2016-07-01 16:40:05.334 INFO 7004 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'connectionFactory' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=rabbitMqConfiguration; factoryMethodName=connectionFactory; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/rabbit/messaging/configuration/RabbitMqConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=taskConsumerConfiguration; factoryMethodName=connectionFactory; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/rabbit/messaging/configuration/TaskConsumerConfiguration.class]]
2016-07-01 16:40:05.334 INFO 7004 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'jsonMessageConverter' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=rabbitMqConfiguration; factoryMethodName=jsonMessageConverter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/rabbit/messaging/configuration/RabbitMqConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=taskConsumerConfiguration; factoryMethodName=jsonMessageConverter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/rabbit/messaging/configuration/TaskConsumerConfiguration.class]]
2016-07-01 16:40:05.868 INFO 7004 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.amqp.rabbit.annotation.RabbitBootstrapConfiguration' of type [class org.springframework.amqp.rabbit.annotation.RabbitBootstrapConfiguration$$EnhancerBySpringCGLIB$$ad9295b0] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-07-01 16:40:06.657 INFO 7004 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
Is there any option to disable this?
While building the jar during test phase it throws following exception.
LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor#76dc36e5]
2016-06-30 15:10:32.989 WARN 21614 --- [cTaskExecutor-1] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it
org.springframework.amqp.AmqpIOException: java.net.SocketTimeoutException: connect timed out
at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:67)
at
You get the log entry 'Overriding bean definition..' when you define a bean with that name more than once.
This leads to the question, which of the, at least two, beans do you use and how are they configured?
Set breakpoint(s) on the constructor(s) of the rabbitListenerContainerFactory bean and see which instances you are creating.
Looking up the stack trace may give you information about why this bean is created, so you can remove the duplicate from your spring configuration.
You can also add breakpoints, where the rabbit connection properties are set.
"connect timed out" also appears, when the given ip is wrong.
Anyway I would not recommend to set the properties in the build script, instead point to the property files on the command line, when you start the application. That allows you to use your build in different environments.
See howto-properties-and-configuration
Why it is throwing while building the jar?
You wrote you are setting the properties with a script during build.
This means that the tests are using those properties and now the tests are failing, may be because the rabbit mq server is not reachable with the provided properties or is not up.
As long as you are overriding beans, you do not really know which instance you use, so you dont really know which properties you use.
Try to log it out, than I am sure you will see....
You can't "lazy load" beans that implement SmartLifecycle (such as the listener container) because the context has to load the bean to call isAutoStartup() to see whether or not the bean should be started.
If the context is being loaded while "building the jar", you must have test cases that are using the beans. You can set autoStartup to false - but your tests will probably fail then.
You can skip running the tests with -DskipTests=true (maven) or -x test (gradle).
I have the same problem in my tests. I don't use rabbit and because the timeouts occur the tests duration increases.
As a simple workaround, you can disable the configuration of queues, exchanges etc. during tests using spring profiles.
Example:
Having the configuration that is disabled if the spring profile "no_rabbit" is present.
#Configuration
#Profile("!no_rabbit")
public class RabbitMQConfig {
#Bean
public Queue queue() {
return QueueBuilder.durable("NAMW").withArgument("x-message-ttl", 3600).build();
}
// more definitions of bean, exchanges etc.
}
Then, in the test simply add the profile "no_rabbit".
#RunWith(SpringRunner.class)
#ActiveProfiles({ "no_rabbit" })
public class TestClass {
...
}
The drawbacks of this approach is that you have to add the profile in every single test that don't uses rabbit. But for my case it's ok until I have a better solution.

Disable table recreation in Spring Boot application

I'm trying to build a simple web application using Spring Boot. When I restart the application all database tables are recreated. I tried setting hibernate.hbm2ddl.auto to update or validate but that doesn't help.
This is my configuration:
#ComponentScan
#EnableAutoConfiguration
#EnableHypermediaSupport
#EnableSpringDataWebSupport
public class ApplicationConfig {
#Bean
public DataSource dataSource() {
DriverManagerDataSource datasource = new DriverManagerDataSource();
datasource.setDriverClassName("org.postgresql.Driver");
datasource.setUrl("jdbc:postgresql://localhost/mydatabase");
datasource.setUsername("myusername");
datasource.setPassword("mypassword");
return datasource;
}
#Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, JpaVendorAdapter jpaVendorAdapter) {
LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
lef.setDataSource(dataSource);
lef.setJpaVendorAdapter(jpaVendorAdapter);
lef.setPackagesToScan("my.domain.package");
Properties jpaProperties = new Properties();
jpaProperties.setProperty("hibernate.hbm2ddl.auto", "update");
lef.setJpaProperties(jpaProperties);
return lef;
}
#Bean
public JpaVendorAdapter jpaVendorAdapter() {
HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
hibernateJpaVendorAdapter.setShowSql(false);
hibernateJpaVendorAdapter.setGenerateDdl(true);
hibernateJpaVendorAdapter.setDatabase(Database.POSTGRESQL);
return hibernateJpaVendorAdapter;
}
#Bean
public PlatformTransactionManager transactionManager() {
return new JpaTransactionManager();
}
public static void main(String[] args) {
SpringApplication.run(ApplicationConfig.class, args);
}
}
Using --debug I get this (somewhat filtered):
2014-02-23 18:17:30.735 INFO 27716 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#66e43eb8: startup date [Sun Feb 23 18:17:30 CET 2014]; root of context hierarchy
2014-02-23 18:17:31.354 INFO 27716 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'pageableResolver': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.data.web.config.HateoasAwareSpringDataWebConfiguration; factoryMethodName=pageableResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/data/web/config/HateoasAwareSpringDataWebConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.data.web.config.HateoasAwareSpringDataWebConfiguration; factoryMethodName=pageableResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/data/web/config/HateoasAwareSpringDataWebConfiguration.class]]
2014-02-23 18:17:31.355 INFO 27716 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'sortResolver': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.data.web.config.HateoasAwareSpringDataWebConfiguration; factoryMethodName=sortResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/data/web/config/HateoasAwareSpringDataWebConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.data.web.config.HateoasAwareSpringDataWebConfiguration; factoryMethodName=sortResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/data/web/config/HateoasAwareSpringDataWebConfiguration.class]]
2014-02-23 18:17:31.726 INFO 27716 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'viewResolver': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=thymeleafConfig; factoryMethodName=viewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [be/**************/******/ThymeleafConfig.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=viewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
2014-02-23 18:17:32.159 INFO 27716 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'transactionManager': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=applicationConfig; factoryMethodName=transactionManager; initMethodName=null; destroyMethodName=(inferred); defined in class **.**************.******.ApplicationConfig] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; factoryMethodName=transactionManager; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]]
2014-02-23 18:17:32.160 INFO 27716 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'entityManagerFactory': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=applicationConfig; factoryMethodName=entityManagerFactory; initMethodName=null; destroyMethodName=(inferred); defined in class **.**************.******.ApplicationConfig] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; factoryMethodName=entityManagerFactory; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]]
2014-02-23 18:17:32.160 INFO 27716 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'jpaVendorAdapter': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=applicationConfig; factoryMethodName=jpaVendorAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class **.**************.******.ApplicationConfig] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; factoryMethodName=jpaVendorAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]]
2014-02-23 18:17:33.031 INFO 27716 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerByCGLIB$$9ca466b9] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2014-02-23 18:17:33.074 INFO 27716 --- [ 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)
2014-02-23 18:17:33.092 INFO 27716 --- [ 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)
2014-02-23 18:17:33.102 INFO 27716 --- [ 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)
2014-02-23 18:17:33.779 INFO 27716 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2014-02-23 18:17:33.779 INFO 27716 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/7.0.42
2014-02-23 18:17:33.909 INFO 27716 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2014-02-23 18:17:33.909 INFO 27716 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3177 ms
2014-02-23 18:17:35.028 INFO 27716 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2014-02-23 18:17:35.028 INFO 27716 --- [ost-startStop-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2014-02-23 18:17:35.124 INFO 27716 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2014-02-23 18:17:35.385 INFO 27716 --- [ost-startStop-1] o.s.j.d.DriverManagerDataSource : Loaded JDBC driver: org.postgresql.Driver
2014-02-23 18:17:35.457 INFO 27716 --- [ost-startStop-1] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2014-02-23 18:17:35.592 INFO 27716 --- [ost-startStop-1] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
2014-02-23 18:17:35.622 INFO 27716 --- [ost-startStop-1] org.hibernate.Version : HHH000412: Hibernate Core {4.2.1.Final}
2014-02-23 18:17:35.627 INFO 27716 --- [ost-startStop-1] org.hibernate.cfg.Environment : HHH000205: Loaded properties from resource hibernate.properties: {hibernate.bytecode.use_reflection_optimizer=false, hibernate.hbm2ddl.auto=validate}
2014-02-23 18:17:35.628 INFO 27716 --- [ost-startStop-1] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2014-02-23 18:17:35.655 INFO 27716 --- [ost-startStop-1] org.hibernate.ejb.Ejb3Configuration : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2014-02-23 18:17:35.899 INFO 27716 --- [ost-startStop-1] o.h.s.j.c.i.ConnectionProviderInitiator : HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
2014-02-23 18:17:36.256 INFO 27716 --- [ost-startStop-1] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL82Dialect
2014-02-23 18:17:36.268 INFO 27716 --- [ost-startStop-1] o.h.e.jdbc.internal.LobCreatorBuilder : HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
2014-02-23 18:17:36.284 INFO 27716 --- [ost-startStop-1] o.h.e.t.i.TransactionFactoryInitiator : HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
2014-02-23 18:17:36.292 INFO 27716 --- [ost-startStop-1] o.h.h.i.ast.ASTQueryTranslatorFactory : HHH000397: Using ASTQueryTranslatorFactory
2014-02-23 18:17:36.481 INFO 27716 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000227: Running hbm2ddl schema export
Hibernate: alter table project drop constraint FK_4725849e7c4543e3885bbd3a3a9
2014-02-23 18:17:36.488 ERROR 27716 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000389: Unsuccessful: alter table project drop constraint FK_4725849e7c4543e3885bbd3a3a9
2014-02-23 18:17:36.488 ERROR 27716 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : ERROR: constraint "fk_4725849e7c4543e3885bbd3a3a9" of relation "project" does not exist
Hibernate: alter table project drop constraint FK_56d354acd26e412daa99d5584ff
2014-02-23 18:17:36.489 ERROR 27716 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000389: Unsuccessful: alter table project drop constraint FK_56d354acd26e412daa99d5584ff
2014-02-23 18:17:36.489 ERROR 27716 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : ERROR: constraint "fk_56d354acd26e412daa99d5584ff" of relation "project" does not exist
Hibernate: drop table if exists company cascade
Hibernate: drop table if exists project cascade
Hibernate: create table company (id serial not null, name varchar(255), primary key (id))
Hibernate: create table project (id serial not null, reference varchar(255), company int4, primary key (id))
Hibernate: alter table project add constraint FK_4725849e7c4543e3885bbd3a3a9 foreign key (company) references company
2014-02-23 18:17:36.577 INFO 27716 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000230: Schema export complete
Your configuration isn't a #Configuration class.
Next to that I suggest that you use the power of Spring Boot. Which means I would suggest removing everything but the DataSource configuration and simply add an application.properties file with the following properties
spring.jpa.database=POSTGRESQL
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=update
This should give you the desired behavior, with less coding.
You could even remove the datasource if you have either commons-dbcp or tomcat-pool in your classpath and adding the following properties
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost/mydatabase
spring.datasource.username=myusername
spring.datasource.password=mypassword
If you are using spring boot, you could do it by configuration over the config file. Hibernate has all this possibilities:
validate (validate the schema)
update (update the schema if are changes)
create (create the schema)
create-drop (create the schema and drop it at the end)
but if you want don't do anything, spring boot add other chance, use as follow:
spring:
jpa:
hibernate:
ddl-auto: none
Your ApplicationConfig is not #Configuration. I imagine that means the Spring Boot autoconfig will also be applied. Can you try adding that?
If you are using a in-memory database then every time you start/stop spring boot application - it will recreate the whole thing unless you mention/configure spring boot to use the database from file system.
update your #Configuration or application.properties for below property
spring.datasource.url=jdbc:h2:file:/Users/user_name/database_file_name
Also check, you should not have spring.datasource.initialization-mode in config.

Resources