Spring #ComponentScan isn't picked up, maybe due to #EnableAutoConfiguration in #SpringBootApplication? - spring

i'm new to SpringBoot and am currently reaching to understand the base functionality for a spring application with hibernate.
I have a package com.yyyyyyyyyyy.coaching and if I put all #Entity definitions there the app runs successfully. I was happy to get up and running quick.
Now I moved one entity to com.yyyyyyyyyyy.i18n.bo since it should later be used elsewhere and hibernate throws the following error:
Caused by: org.hibernate.AnnotationException: #OneToOne or #ManyToOne on com.yyyyyyyyyyy.coaching.bo.Topic.descriptionStrings references an unknown entity: com.yyyyyyyyyyy.i18n.bo.Localized
(see below for the full --debug application startup)
I understand that #ComponentScan should be used to specify which packages are scanned for annotations.
I have double checked that javax.persistence.Entity is used everywhere and not the one from the hibernate package.
Here is my program entry point:
#SpringBootApplication(scanBasePackages={"com.yyyyyyyyyyy"})
//#Configuration
//#ComponentScan(basePackages={"com.yyyyyyyyyyy.coaching", "com.yyyyyyyyyyy.i18n"})
#Import(AppConfig.class)
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
It doesn't find the Entity with scanBasePackages, with ComponentScan on the main class and also when using #Import and another config class "AppConfig". I also tried to use the ApplicationBuilder instead of SpringApplication like this new SpringApplicationBuilder().sources(AppConfig.class).main(DemoApplication.class).run(args); but to no avail.
What I can see from the debug output is the line:
2015-11-18 08:08:48.407 DEBUG 13780 --- [ main] o.s.b.a.AutoConfigurationPackages : #EnableAutoConfiguration was declared on a class in the package 'com.yyyyyyyyyyy.coaching'. Automatic #Repository and #Entity scanning is enabled.
I suppose this doesn't hurt as it comes from the #SpringBootApplication annotation
The AppConfig class doesn't seem to be included either, as I added debug output which isn't printed.
#Configuration
//#Profile("production")
#ComponentScan(basePackages={"com.yyyyyyyyyyy.coaching", "com.yyyyyyyyyyy.i18n"})
public class AppConfig {
public AppConfig() {
System.out.println("------------------------------Init AppConfig-------------------------");
}
#PostConstruct
public void doSomething() {
System.out.println("------------------------------Done AppConfig-------------------------");
}
}
Any help/ideas on this?
Thanks.
Edit, prj structure:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.3.0.RELEASE)
2015-11-18 08:08:47.048 INFO 13780 --- [ main] c.yyyyyyyyyyy.coaching.DemoApplication : Starting DemoApplication on Suse with PID 13780 (started by Klaus in C:\Users\Klaus\Downloads\demo (1)\demo)
2015-11-18 08:08:47.051 INFO 13780 --- [ main] c.yyyyyyyyyyy.coaching.DemoApplication : No profiles are active
2015-11-18 08:08:47.051 DEBUG 13780 --- [ main] o.s.boot.SpringApplication : Loading source class com.yyyyyyyyyyy.coaching.DemoApplication
2015-11-18 08:08:47.098 DEBUG 13780 --- [ main] o.s.b.c.c.ConfigFileApplicationListener : Loaded config file 'classpath:/application.properties'
2015-11-18 08:08:47.098 DEBUG 13780 --- [ main] o.s.b.c.c.ConfigFileApplicationListener : Skipped (empty) config file 'classpath:/application.properties' for profile default
2015-11-18 08:08:47.103 INFO 13780 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#1fc32e4f: startup date [Wed Nov 18 08:08:47 CET 2015]; root of context hierarchy
2015-11-18 08:08:47.106 DEBUG 13780 --- [ main] ationConfigEmbeddedWebApplicationContext : Bean factory for org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#1fc32e4f: org.springframework.beans.factory.support.DefaultListableBeanFactory#7a1a3478: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication]; root of factory hierarchy
2015-11-18 08:08:48.286 INFO 13780 --- [ 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]]
2015-11-18 08:08:48.407 DEBUG 13780 --- [ main] o.s.b.a.AutoConfigurationPackages : #EnableAutoConfiguration was declared on a class in the package 'com.yyyyyyyyyyy.coaching'. Automatic #Repository and #Entity scanning is enabled.
2015-11-18 08:08:48.995 INFO 13780 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$4e01ef7c] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2015-11-18 08:08:49.038 DEBUG 13780 --- [ main] ationConfigEmbeddedWebApplicationContext : Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource#2e17a321]
2015-11-18 08:08:49.038 DEBUG 13780 --- [ main] ationConfigEmbeddedWebApplicationContext : Using ApplicationEventMulticaster [org.springframework.context.event.SimpleApplicationEventMulticaster#521bb1a4]
2015-11-18 08:08:49.368 DEBUG 13780 --- [ main] .t.TomcatEmbeddedServletContainerFactory : Code archive: C:\Users\Klaus\.m2\repository\org\springframework\boot\spring-boot\1.3.0.RELEASE\spring-boot-1.3.0.RELEASE.jar
2015-11-18 08:08:49.369 DEBUG 13780 --- [ main] .t.TomcatEmbeddedServletContainerFactory : Code archive: C:\Users\Klaus\.m2\repository\org\springframework\boot\spring-boot\1.3.0.RELEASE\spring-boot-1.3.0.RELEASE.jar
2015-11-18 08:08:49.369 DEBUG 13780 --- [ main] .t.TomcatEmbeddedServletContainerFactory : None of the document roots [src/main/webapp, public, static] point to a directory and will be ignored.
2015-11-18 08:08:49.419 INFO 13780 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2015-11-18 08:08:49.433 INFO 13780 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2015-11-18 08:08:49.434 INFO 13780 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.28
2015-11-18 08:08:49.566 INFO 13780 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2015-11-18 08:08:49.566 INFO 13780 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2467 ms
[..]
2015-11-18 08:08:49.960 INFO 13780 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2015-11-18 08:08:49.960 INFO 13780 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2015-11-18 08:08:49.961 INFO 13780 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2015-11-18 08:08:49.961 INFO 13780 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2015-11-18 08:08:49.982 DEBUG 13780 --- [ost-startStop-1] o.s.b.c.web.OrderedRequestContextFilter : Initializing filter 'requestContextFilter'
2015-11-18 08:08:49.984 DEBUG 13780 --- [ost-startStop-1] o.s.b.c.web.OrderedRequestContextFilter : Filter 'requestContextFilter' configured successfully
2015-11-18 08:08:49.985 DEBUG 13780 --- [ost-startStop-1] .s.b.c.w.OrderedHttpPutFormContentFilter : Initializing filter 'httpPutFormContentFilter'
2015-11-18 08:08:49.985 DEBUG 13780 --- [ost-startStop-1] .s.b.c.w.OrderedHttpPutFormContentFilter : Filter 'httpPutFormContentFilter' configured successfully
2015-11-18 08:08:49.985 DEBUG 13780 --- [ost-startStop-1] o.s.b.c.w.OrderedHiddenHttpMethodFilter : Initializing filter 'hiddenHttpMethodFilter'
2015-11-18 08:08:49.985 DEBUG 13780 --- [ost-startStop-1] o.s.b.c.w.OrderedHiddenHttpMethodFilter : Filter 'hiddenHttpMethodFilter' configured successfully
2015-11-18 08:08:49.985 DEBUG 13780 --- [ost-startStop-1] o.s.b.c.w.OrderedCharacterEncodingFilter : Initializing filter 'characterEncodingFilter'
2015-11-18 08:08:49.985 DEBUG 13780 --- [ost-startStop-1] o.s.b.c.w.OrderedCharacterEncodingFilter : Filter 'characterEncodingFilter' configured successfully
2015-11-18 08:08:50.825 INFO 13780 --- [ main] liquibase : Successfully acquired change log lock
2015-11-18 08:08:50.917 INFO 13780 --- [ main] liquibase : Reading from broadleaf.DATABASECHANGELOG
2015-11-18 08:08:50.926 INFO 13780 --- [ main] liquibase : Successfully released change log lock
2015-11-18 08:08:51.116 INFO 13780 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2015-11-18 08:08:51.128 INFO 13780 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2015-11-18 08:08:51.210 INFO 13780 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {4.3.11.Final}
2015-11-18 08:08:51.211 INFO 13780 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2015-11-18 08:08:51.214 INFO 13780 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2015-11-18 08:08:51.394 INFO 13780 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2015-11-18 08:08:51.441 INFO 13780 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2015-11-18 08:08:51.557 WARN 13780 --- [ 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: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
2015-11-18 08:08:51.567 INFO 13780 --- [ main] o.apache.catalina.core.StandardService : Stopping service Tomcat
2015-11-18 08:08:51.574 INFO 13780 --- [ main] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [ ...
2015-11-18 08:08:51.578 ERROR 13780 --- [ 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: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1051) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:828) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:347) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:295) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1112) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1101) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
at com.yyyyyyyyyyy.coaching.DemoApplication.main(DemoApplication.java:23) [classes/:na]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1249) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access$600(EntityManagerFactoryBuilderImpl.java:120) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:860) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343) ~[spring-orm-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318) ~[spring-orm-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
... 16 common frames omitted
Caused by: org.hibernate.AnnotationException: #OneToOne or #ManyToOne on com.yyyyyyyyyyy.coaching.bo.Topic.descriptionStrings references an unknown entity: com.yyyyyyyyyyy.i18n.bo.Localized

Move DemoApplication class to com.yyyyyyyyyyy package and everything should work. Everything which is in com.yyyyyyyyyyy should be picked automatically.
Check this out how spring boot recommend structuring
UPDATE:
also as you saw in the ref documentation add
add #EntityScan(basePackages={"com.yyyyyyyyyyy.coaching", "com.yyyyyyyyyyy.i18n"})to DemoApplication will work.

Related

Illegal state exception: Error during attachment using: co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent

I just created one application with springboot , used the Elastic APM attacher of APM tool. When i run the apm attacher, it generates error exception as shown below. Code used to generate the error:
package com.howtodoinjava.demo;
import org.springframework.boot.SpringApplication;
import co.elastic.apm.attach.*;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class SpringBootDemoApplication {
public static void main(String[] args) {
ElasticApmAttacher.attach();
SpringApplication.run(SpringBootDemoApplication.class, args);
}
}
---------------------------------------------------------------------
IDE: Eclipse
Spring boot
Error exception :
Exception in thread "main" java.lang.IllegalStateException: Error during attachment using: co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound#6debcae2
at co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:608)
at co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:268)
at co.elastic.apm.attach.ElasticApmAttacher.attach(ElasticApmAttacher.java:166)
at co.elastic.apm.attach.ElasticApmAttacher.attach(ElasticApmAttacher.java:120)
at co.elastic.apm.attach.ElasticApmAttacher.attach(ElasticApmAttacher.java:77)
at com.howtodoinjava.demo.SpringBootDemoApplication.main(SpringBootDemoApplication.java:11)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at co.elastic.apm.attach.bytebuddy.agent.Attacher.install(Attacher.java:106)
at co.elastic.apm.attach.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:603)
... 5 more
Caused by: java.lang.NoSuchMethodError: com.sun.jna.Native.load(Ljava/lang/String;Ljava/lang/Class;Ljava/util/Map;)Lcom/sun/jna/Library;
at com.sun.jna.platform.win32.Kernel32.<clinit>(Kernel32.java:43)
at co.elastic.apm.attach.bytebuddy.agent.VirtualMachine$ForHotSpot$Connection$ForJnaWindowsNamedPipe$Factory.connect(VirtualMachine.java:1235)
at co.elastic.apm.attach.bytebuddy.agent.VirtualMachine$ForHotSpot.attach(VirtualMachine.java:256)
at co.elastic.apm.attach.bytebuddy.agent.VirtualMachine$ForHotSpot.attach(VirtualMachine.java:239)
... 11 more
---------------------------
But if I try to run the application commenting the line i.e //ElasticApmAttacher.attach(); from same code, it runs successfully
package com.howtodoinjava.demo;
import org.springframework.boot.SpringApplication;
import co.elastic.apm.attach.*;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class SpringBootDemoApplication {
public static void main(String[] args) {
//ElasticApmAttacher.attach();
SpringApplication.run(SpringBootDemoApplication.class, args);
}
}
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.4.0.RELEASE)
2019-12-07 22:58:30.086 INFO 16984 --- [ main] c.h.demo.SpringBootDemoApplication : Starting SpringBootDemoApplication on LP-ArvindK with PID 16984 (C:\Users\arvind.kumar\Downloads\springbootdemo-hello-world-rest\springbootdemo\target\classes started by Arvind.Kumar in C:\Users\arvind.kumar\Downloads\springbootdemo-hello-world-rest\springbootdemo)
2019-12-07 22:58:30.090 INFO 16984 --- [ main] c.h.demo.SpringBootDemoApplication : No active profile set, falling back to default profiles: default
2019-12-07 22:58:30.130 INFO 16984 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#647fd8ce: startup date [Sat Dec 07 22:58:30 IST 2019]; root of context hierarchy
2019-12-07 22:58:31.046 INFO 16984 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2019-12-07 22:58:31.107 INFO 16984 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$64c40b86] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-12-07 22:58:31.431 INFO 16984 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8081 (http)
2019-12-07 22:58:31.439 INFO 16984 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2019-12-07 22:58:31.439 INFO 16984 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.4
2019-12-07 22:58:31.610 INFO 16984 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-12-07 22:58:31.610 INFO 16984 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1484 ms
2019-12-07 22:58:31.734 INFO 16984 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2019-12-07 22:58:31.734 INFO 16984 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-12-07 22:58:31.734 INFO 16984 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-12-07 22:58:31.734 INFO 16984 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2019-12-07 22:58:31.734 INFO 16984 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2019-12-07 22:58:32.038 INFO 16984 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2019-12-07 22:58:32.050 INFO 16984 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-12-07 22:58:32.138 INFO 16984 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.0.9.Final}
2019-12-07 22:58:32.142 INFO 16984 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2019-12-07 22:58:32.142 INFO 16984 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2019-12-07 22:58:32.230 INFO 16984 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2019-12-07 22:58:32.350 INFO 16984 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect
2019-12-07 22:58:32.489 INFO 16984 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000227: Running hbm2ddl schema export
2019-12-07 22:58:32.489 INFO 16984 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000230: Schema export complete
2019-12-07 22:58:32.501 INFO 16984 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-12-07 22:58:32.830 INFO 16984 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#647fd8ce: startup date [Sat Dec 07 22:58:30 IST 2019]; root of context hierarchy
2019-12-07 22:58:32.878 INFO 16984 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto public java.util.List<com.howtodoinjava.demo.model.Employee> com.howtodoinjava.demo.controller.EmployeeController.getEmployees()
2019-12-07 22:58:32.878 INFO 16984 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2019-12-07 22:58:32.878 INFO 16984 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2019-12-07 22:58:32.910 INFO 16984 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-12-07 22:58:32.910 INFO 16984 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-12-07 22:58:32.938 INFO 16984 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-12-07 22:58:33.167 INFO 16984 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2019-12-07 22:58:33.205 INFO 16984 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8081 (http)
2019-12-07 22:58:33.209 INFO 16984 --- [ main] c.h.demo.SpringBootDemoApplication : Started SpringBootDemoApplication in 3.365 seconds (JVM running for 4.327)
i am searching for solution but so far clueless. Can someone please suggest how to resolve it
The exception comes from the constructur of the Kernel32 class which is a class of the Maven coordinate net.java.dev.jna:jna-platform which itself depends on net.java.dev.jna:jna. It seems to me like you have to incompatible versions of those dependencies on the class path.
I assume that you use version 4 of JNA core and version 5 of JNA platform. Upgrade the first or downgrade the latter and the error should disappear.

Error running gradle bootrun

I am trying to do gradle bootRun using IntelliJ, but this error appears:
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':bootRun'.
Process 'command 'C:\Program Files\Java\jdk1.8.0_131\bin\java.exe'' finished with non-zero exit value 1
In the Console I have this:
2017-06-21 10:13:54.177 INFO 12008 --- [ main] com.nice_system.nicemedia.ApplicationKt : Starting ApplicationKt on DESKTOP-GHI2UHL with PID 12008 (started by Darja Strahlberg in C:\Users\Darja Strahlberg
\code\versuch\nto_niceMediaServer)
2017-06-21 10:13:54.182 INFO 12008 --- [ main] com.nice_system.nicemedia.ApplicationKt : No active profile set, falling back to default profiles: default
2017-06-21 10:13:54.310 INFO 12008 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#5be6e01c: start
up date [Wed Jun 21 10:13:54 CEST 2017]; root of context hierarchy
2017-06-21 10:13:56.234 INFO 12008 --- [ 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$Ena
bleWebMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurat
ion$EnableWebMvcConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframew
ork.data.rest.webmvc.config.RepositoryRestMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/data/re
st/webmvc/config/RepositoryRestMvcConfiguration.class]]
2017-06-21 10:13:57.102 INFO 12008 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframe
work.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$dc898557] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-06-21 10:13:57.776 INFO 12008 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8081 (http)
2017-06-21 10:13:57.797 INFO 12008 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2017-06-21 10:13:57.800 INFO 12008 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.14
2017-06-21 10:13:58.025 INFO 12008 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-06-21 10:13:58.025 INFO 12008 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3719 ms
2017-06-21 10:13:58.319 INFO 12008 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-06-21 10:13:58.325 INFO 12008 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-06-21 10:13:58.325 INFO 12008 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-06-21 10:13:58.325 INFO 12008 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-06-21 10:13:58.325 INFO 12008 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally u
nnecessary.
2017-06-21 10:14:00.929 ERROR 12008 --- [ main] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
This is my build.gradle file:
plugins {
id "org.jetbrains.kotlin.jvm" version "1.1.2"
id "org.jetbrains.kotlin.plugin.noarg" version "1.1.2"
id "org.jetbrains.kotlin.plugin.jpa" version "1.1.2"
id "org.springframework.boot" version "1.5.3.RELEASE"}
jar {
baseName = 'nicemedia-api'
version = '0.1.0'
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib"
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.springframework.boot:spring-boot-starter-data-jpa"
compile "org.springframework.boot:spring-boot-starter-data-rest"
testCompile "org.springframework.boot:spring-boot-starter-test"
runtime "mysql:mysql-connector-java:6.0.6"
runtime "com.h2database:h2"
}
repositories {
mavenCentral()
}

Spring Boot JPA multiple datasource error

I wanted to connect my spring boot app to 2 databases . So according to a tutorial i created 2 config classes.
Config Class 1
#Configuration
#EnableTransactionManagement
#PropertySource({ "classpath:database-configs.properties" })
#EnableJpaRepositories(
basePackages = {"com.dialog.pod.ideabiz_admin.data_access_objects"},
entityManagerFactoryRef = "adminEntityManagerFactory",
transactionManagerRef = "adminTransactionManager")
public class IdeabizAdminConfig {
#Autowired
private Environment env;
#Bean
PlatformTransactionManager adminTransactionManager() {
return new JpaTransactionManager(adminEntityManagerFactory().getObject());
}
#Bean
LocalContainerEntityManagerFactoryBean adminEntityManagerFactory() {
HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
// jpaVendorAdapter.setGenerateDdl(true);
LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
factoryBean.setDataSource(adminDataSource());
factoryBean.setJpaVendorAdapter(jpaVendorAdapter);
factoryBean.setPackagesToScan("com.dialog.pod.ideabiz_admin.models");
factoryBean.setJpaPropertyMap(jpaProperties());
factoryBean.setPersistenceUnitName("adminDataSource");
return factoryBean;
}
#Bean
DataSource adminDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(env.getProperty("admin.jdbc.driverClassName"));
dataSource.setUrl(env.getProperty("admin.jdbc.url"));
dataSource.setUsername(env.getProperty("admin.jdbc.username"));
dataSource.setPassword(env.getProperty("admin.jdbc.password"));
return dataSource;
}
private Map<String, Object> jpaProperties() {
Map<String, Object> props = new HashMap<>();
props.put("hibernate.implicit_naming_strategy","org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl");
props.put("hibernate.physical_naming_strategy","com.dialog.pod.PhysicalNamingStrategyImpl");
return props;
}
}
Config Class 2
#Configuration
#EnableTransactionManagement
#PropertySource({ "classpath:database-configs.properties" })
#EnableJpaRepositories(
basePackages = {"com.dialog.pod.ideabiz_log_summary.data_access_objects"},
entityManagerFactoryRef = "sumLogEntityManagerFactory",
transactionManagerRef = "sumLogTransactionManager")
public class IdeabizLogSummaryConfig {
#Autowired
private Environment env;
#Bean
PlatformTransactionManager sumLogTransactionManager() {
return new JpaTransactionManager(sumLogEntityManagerFactory().getObject());
}
#Bean
LocalContainerEntityManagerFactoryBean sumLogEntityManagerFactory() {
HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
// jpaVendorAdapter.setGenerateDdl(true);
LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
factoryBean.setDataSource(adminDataSource());
factoryBean.setJpaVendorAdapter(jpaVendorAdapter);
factoryBean.setPackagesToScan("com.dialog.pod.ideabiz_log_summary.models");
factoryBean.setJpaPropertyMap(jpaProperties());
factoryBean.setPersistenceUnitName("sumLogDataSource");
return factoryBean;
}
#Bean
DataSource adminDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(env.getProperty("sumlog.jdbc.driverClassName"));
dataSource.setUrl(env.getProperty("sumlog.jdbc.url"));
dataSource.setUsername(env.getProperty("sumlog.jdbc.username"));
dataSource.setPassword(env.getProperty("sumlog.jdbc.password"));
return dataSource;
}
private Map<String, Object> jpaProperties() {
Map<String, Object> props = new HashMap<>();
props.put("hibernate.implicit_naming_strategy","org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl");
props.put("hibernate.physical_naming_strategy","com.dialog.pod.PhysicalNamingStrategyImpl");
return props;
}
}
Application Class
#SpringBootApplication
#EnableAutoConfiguration (exclude = { DataSourceAutoConfiguration.class })
#Configuration
#ComponentScan
public class PodApiApplication {
public static void main(String[] args) {
SpringApplication.run(PodApiApplication.class, args);
}
#Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurerAdapter() {
#Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/").allowedOrigins("*");
}
};
}
}
When i try to run the app i get following error.
***************************
APPLICATION FAILED TO START
***************************
Description:
Method requestMappingHandlerMapping in org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration required a single bean, but 2 were found:
- adminEntityManagerFactory: defined by method 'adminEntityManagerFactory' in class path resource [com/dialog/pod/ideabiz_admin/IdeabizAdminConfig.class]
- sumLogEntityManagerFactory: defined by method 'sumLogEntityManagerFactory' in class path resource [com/dialog/pod/ideabiz_log_summary/IdeabizLogSummaryConfig.class]
Action:
Consider marking one of the beans as #Primary, updating the consumer to accept multiple beans, or using #Qualifier to identify the bean that should be consumed
Process finished with exit code 1
I put #Primary to the first config class(according to another tutorial). When i do that datasource in the first config class works. Problem is when i do this first datasource also applied to all the jparepositories.
I'm new to Spring boot. I have been trying to solve this problem for over 5 hours :( . Thanks in advance for any help you are able to provide.
Full Log
2017-01-27 00:52:39.713 INFO 6704 --- [ main] com.dialog.pod.PodApiApplication : Starting PodApiApplication on DESKTOP-4B89ITN with PID 6704 (started by y2ksh in H:\Spring MVC Workspace\platform-overview-dashboard\PODApi)
2017-01-27 00:52:39.718 INFO 6704 --- [ main] com.dialog.pod.PodApiApplication : No active profile set, falling back to default profiles: default
2017-01-27 00:52:39.938 INFO 6704 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#6e171cd7: startup date [Fri Jan 27 00:52:39 IST 2017]; root of context hierarchy
2017-01-27 00:52:41.712 INFO 6704 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'adminDataSource' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=ideabizAdminConfig; factoryMethodName=adminDataSource; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/dialog/pod/ideabiz_admin/IdeabizAdminConfig.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=ideabizLogSummaryConfig; factoryMethodName=adminDataSource; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/dialog/pod/ideabiz_log_summary/IdeabizLogSummaryConfig.class]]
2017-01-27 00:52:42.804 INFO 6704 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$3cc0fc3] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-01-27 00:52:43.594 INFO 6704 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8081 (http)
2017-01-27 00:52:43.609 INFO 6704 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2017-01-27 00:52:43.609 INFO 6704 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.6
2017-01-27 00:52:43.810 INFO 6704 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-01-27 00:52:43.810 INFO 6704 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3891 ms
2017-01-27 00:52:44.247 INFO 6704 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-01-27 00:52:44.253 INFO 6704 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'metricFilter' to: [/*]
2017-01-27 00:52:44.254 INFO 6704 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-01-27 00:52:44.254 INFO 6704 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-01-27 00:52:44.254 INFO 6704 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-01-27 00:52:44.254 INFO 6704 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2017-01-27 00:52:44.255 INFO 6704 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'webRequestLoggingFilter' to: [/*]
2017-01-27 00:52:44.255 INFO 6704 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'applicationContextIdFilter' to: [/*]
2017-01-27 00:52:44.367 INFO 6704 --- [ main] o.s.j.d.DriverManagerDataSource : Loaded JDBC driver: com.mysql.jdbc.Driver
2017-01-27 00:52:44.403 INFO 6704 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'adminDataSource'
2017-01-27 00:52:44.435 INFO 6704 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: adminDataSource
...]
2017-01-27 00:52:44.634 INFO 6704 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.0.11.Final}
2017-01-27 00:52:44.636 INFO 6704 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2017-01-27 00:52:44.641 INFO 6704 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2017-01-27 00:52:44.725 INFO 6704 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2017-01-27 00:52:45.302 INFO 6704 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2017-01-27 00:52:46.178 INFO 6704 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'adminDataSource'
2017-01-27 00:52:46.189 INFO 6704 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'sumLogDataSource'
2017-01-27 00:52:46.190 INFO 6704 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: sumLogDataSource
...]
2017-01-27 00:52:46.228 INFO 6704 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2017-01-27 00:52:46.291 INFO 6704 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'sumLogDataSource'
2017-01-27 00:52:46.695 INFO 6704 --- [ main] o.h.h.i.QueryTranslatorFactoryInitiator : HHH000397: Using ASTQueryTranslatorFactory
2017-01-27 00:52:46.947 INFO 6704 --- [ main] o.h.h.i.QueryTranslatorFactoryInitiator : HHH000397: Using ASTQueryTranslatorFactory
2017-01-27 00:52:47.496 INFO 6704 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#6e171cd7: startup date [Fri Jan 27 00:52:39 IST 2017]; root of context hierarchy
2017-01-27 00:52:47.560 WARN 6704 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping]: Factory method 'requestMappingHandlerMapping' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'openEntityManagerInViewInterceptor' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration$JpaWebConfiguration$JpaWebMvcConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'javax.persistence.EntityManagerFactory' available: expected single matching bean but found 2: adminEntityManagerFactory,sumLogEntityManagerFactory
2017-01-27 00:52:47.562 INFO 6704 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'sumLogDataSource'
2017-01-27 00:52:47.563 INFO 6704 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'adminDataSource'
2017-01-27 00:52:47.566 INFO 6704 --- [ main] o.apache.catalina.core.StandardService : Stopping service Tomcat
2017-01-27 00:52:47.586 INFO 6704 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-01-27 00:52:47.592 ERROR 6704 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Method requestMappingHandlerMapping in org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration required a single bean, but 2 were found:
- adminEntityManagerFactory: defined by method 'adminEntityManagerFactory' in class path resource [com/dialog/pod/ideabiz_admin/IdeabizAdminConfig.class]
- sumLogEntityManagerFactory: defined by method 'sumLogEntityManagerFactory' in class path resource [com/dialog/pod/ideabiz_log_summary/IdeabizLogSummaryConfig.class]
Action:
Consider marking one of the beans as #Primary, updating the consumer to accept multiple beans, or using #Qualifier to identify the bean that should be consumed
Process finished with exit code 1
Mark one of the beans as primary
#Primary
#Bean
public EntityManagerFactory entityManagerFactory() {
}
Your Spring Boot application implicitly activates Spring Web Mvc via #WebMvcAutoConfiguration which is triggered by having, among others, Servlet.class in your class path. This #WebMvcAutoConfiguration requires a bean of type EntityManagerFactory. However, you have registered two such beans adminEntityManagerFactory and sumLogEntityManagerFactory. So you have to tell Spring Web Mvc which is your preferred one via #Primary on top of the respective #Bean method. Alternatively if you don't need Web Mvc autoconfiguration switch it off by #EnableAutoConfiguration(exclude={WebMvcAutoConfiguration}) and configure Web Mvc manually.
It turns out i used same method name for both datasource beans . This was the reason why only one data source used for all jparepos. Thanks #Javatar81 for explaining how bean naming works

AspectJ LTW not working with Spring Boot on unmanaged classes

I'm facing a problem on a large scale application using SpringBoot and AspectJ for logging purposes. The logging works fine for Spring Beans, but does not work for unmanaged classes (the ones I instantiate with 'new').
I've created a sample app where you can see the problem happening, you can access it here:
https://bitbucket.org/tomkro/stack_question
The application is pretty simple, the Gradle file is a common with the standard Spring Boot starters.
There are 5 relevant classes here.
Application.java, which is the main class:
#EnableAspectJAutoProxy
#EnableLoadTimeWeaving(aspectjWeaving= EnableLoadTimeWeaving.AspectJWeaving.ENABLED)
#SpringBootApplication(scanBasePackages = "com.test.*")
public class Application {
public static void main(final String[] args) {
SpringApplication.run(Application.class, args);
}
}
The AspectConfig file (which for the sake of simplicity also defines the RestController, could be easily separated files)
#RestController
#Configuration
#ComponentScan(basePackages = {"com.test"})
public class AspectConfig {
#Bean
public TestLogger testLogger(){
return new TestLogger();
}
#Autowired
TestClass testClass;
#RequestMapping("/")
public int get() {
return testClass.methodFromClass1();
}
}
The TestLogger, which defines the aspect for this app:
#Aspect
public class TestLogger {
public TestLogger() {
}
#Around("execution( * com.test.classes..*.*(..))")
public Object aroundExecution(ProceedingJoinPoint pjp) throws Throwable {
String packageName = pjp.getSignature().getDeclaringTypeName();
String methodName = pjp.getSignature().getName();
long start = System.currentTimeMillis();
System.out.println(packageName + "." + methodName + " - Starting execution ");
Object output = pjp.proceed();
Long elapsedTime = System.currentTimeMillis() - start;
System.out.println(packageName + "." + methodName + " - Ending execution ["+elapsedTime+" ms]");
return output;
}
}
And then there's two files, one managed by Spring, the other not:
TestClass1:
#Component
public class TestClass {
public int methodFromClass1() {
TestClass2 test = new TestClass2();
return test.methodFromClass2();
}
}
TestClass2
public class TestClass2 {
public int methodFromClass2() {
int a = 10;
int b = 5;
return b + a;
}
}
Also there's the aop.xml file in META-INF which specifies the Aspect
<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
<aspectj>
<weaver option="-debug">
<!-- only weave classes in our application-specific packages -->
<include within="com.test.*"/>
</weaver>
<aspects>
<!-- weave in just this aspect -->
<aspect name="com.test.utilities.TestLogger"/>
</aspects>
</aspectj>
I followed most of this build using the tutorial on the Spring documentation here , and I've been scratching my head for two days now and I can't figure out what's happening. The managed Bean logs fine, but the unmanaged one is not being logged.
I'm using the run.bat included in the project for starting, basically it does this:
call gradle build
java -javaagent:.\src\main\resources\aspectjweaver.jar -javaagent:.\src\main\resources\spring-instrument.jar -jar build\libs\Test-0.0.1-SNAPSHOT.jar
Both jars are the latest. Usually you only would need of the JAR's, but I saw someone using both and gave it a shot. This is the output after startup and execution of a call to "localhost:8080"
[LaunchedURLClassLoader#6d8a00e3] warning javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.3.0.RELEASE)
2016-04-08 15:21:44.116 INFO 20400 --- [ main] com.test.Application : Starting Application on PC000BR23205 with PID 20400 (C:\git\Test\build\libs\Test-0.0.1-SNAPSHOT.jar started by tkroth in C:\git\T
est)
2016-04-08 15:21:44.120 INFO 20400 --- [ main] com.test.Application : No profiles are active
2016-04-08 15:21:44.294 INFO 20400 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#2cd72cea: startup date [Fri Ap
r 08 15:21:44 BRT 2016]; root of context hierarchy
2016-04-08 15:21:44.950 INFO 20400 --- [ 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; fa
ctoryMethodName=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$W
ebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAut
oConfigurationAdapter.class]]
2016-04-08 15:21:45.872 INFO 20400 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-04-08 15:21:45.888 INFO 20400 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2016-04-08 15:21:45.891 INFO 20400 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.28
2016-04-08 15:21:45.987 INFO 20400 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2016-04-08 15:21:45.987 INFO 20400 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1695 ms
2016-04-08 15:21:46.342 INFO 20400 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2016-04-08 15:21:46.347 INFO 20400 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-04-08 15:21:46.348 INFO 20400 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-04-08 15:21:46.349 INFO 20400 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-04-08 15:21:46.349 INFO 20400 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2016-04-08 15:21:46.439 INFO 20400 --- [ main] o.s.c.w.DefaultContextLoadTimeWeaver : Found Spring's JVM agent for instrumentation
2016-04-08 15:21:46.455 INFO 20400 --- [ main] o.s.c.w.DefaultContextLoadTimeWeaver : Found Spring's JVM agent for instrumentation
[LaunchedURLClassLoader#6d8a00e3] warning javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified
2016-04-08 15:21:46.781 INFO 20400 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#2cd72cea:
startup date [Fri Apr 08 15:21:44 BRT 2016]; root of context hierarchy
2016-04-08 15:21:46.874 INFO 20400 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto public int com.test.configuration.AspectConfig.get()
2016-04-08 15:21:46.877 INFO 20400 --- [ 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.sp
ringframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2016-04-08 15:21:46.878 INFO 20400 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoco
nfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
2016-04-08 15:21:46.912 INFO 20400 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-04-08 15:21:46.912 INFO 20400 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-04-08 15:21:47.030 INFO 20400 --- [ 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-08 15:21:47.133 INFO 20400 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-04-08 15:21:47.204 INFO 20400 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-04-08 15:21:47.210 INFO 20400 --- [ main] com.test.Application : Started Application in 3.481 seconds (JVM running for 4.306)
2016-04-08 15:21:51.680 INFO 20400 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2016-04-08 15:21:51.680 INFO 20400 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2016-04-08 15:21:51.704 INFO 20400 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 23 ms
com.test.classes.TestClass.methodFromClass1 - Starting execution
com.test.classes.TestClass.methodFromClass1 - Ending execution [15 ms]
As you can see, TestClass2 is never logged, although it's called. What am I missing here?
The real question is, how can I make non-beans to be handled by LTW in a SpringBoot environment? Feel free to commit changes on the repository I provided above.

Spring Hibernate connecting to AWS RDS error

I am able to run my web application when I point to my local database:
Server version: 5.6.26 MySQL Community Server (GPL)
2015-10-10 13:37:20.598 INFO 2872 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'transactionInterceptor' of type [class org.springframework.transaction.interceptor.TransactionInterceptor] is not eligible for getting processed by all BeanPostProce
ssors (for example: not eligible for auto-proxying)
2015-10-10 13:37:20.657 INFO 2872 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.config.internalTransactionAdvisor' of type [class org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAd
visor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2015-10-10 13:37:22.419 INFO 2872 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2015-10-10 13:37:23.022 INFO 2872 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2015-10-10 13:37:23.025 INFO 2872 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.23
2015-10-10 13:37:23.320 INFO 2872 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2015-10-10 13:37:23.321 INFO 2872 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 11366 ms
2015-10-10 13:37:27.384 INFO 2872 --- [ost-startStop-1] o.s.j.d.DriverManagerDataSource : Loaded JDBC driver: com.mysql.jdbc.Driver
2015-10-10 13:37:28.649 INFO 2872 --- [ost-startStop-1] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: org.springframework.security.web.util.matcher.AnyRequestMatcher#1, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegratio
nFilter#28ba6f1f, org.springframework.security.web.context.SecurityContextPersistenceFilter#4d9d07dd, org.springframework.security.web.header.HeaderWriterFilter#6ea013e0, org.springframework.security.web.csrf.CsrfFilter#695c931a, org.springframework.security.web.authenti
cation.logout.LogoutFilter#2243a064, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#288989d8, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#2b027994, org.springframework.security.web.servletapi.SecurityContext
HolderAwareRequestFilter#69764da4, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#4c99f499, org.springframework.security.web.session.SessionManagementFilter#484a49a7, org.springframework.security.web.access.ExceptionTranslationFilter#46e34c
8f, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#f2c41d9]
2015-10-10 13:37:29.010 INFO 2872 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2015-10-10 13:37:29.039 INFO 2872 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2015-10-10 13:37:29.041 INFO 2872 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2015-10-10 13:37:29.041 INFO 2872 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2015-10-10 13:37:30.042 INFO 2872 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2015-10-10 13:37:30.117 INFO 2872 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2015-10-10 13:37:30.384 INFO 2872 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {4.3.10.Final}
2015-10-10 13:37:30.404 INFO 2872 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2015-10-10 13:37:30.408 INFO 2872 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2015-10-10 13:37:31.228 INFO 2872 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2015-10-10 13:37:31.426 INFO 2872 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2015-10-10 13:37:31.949 INFO 2872 --- [ main] o.h.h.i.ast.ASTQueryTranslatorFactory : HHH000397: Using ASTQueryTranslatorFactory
I am able to access my 2 AWS RDS databases from my desktop using Hedidi. The databases have different versions:
MySQL 5.6.23
MySQL 5.1.73a
But when I point to my database and run again I get the follow exception:
2015-10-10 13:42:40.605 INFO 512 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2015-10-10 13:42:41.142 INFO 512 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2015-10-10 13:42:41.146 INFO 512 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.23
2015-10-10 13:42:41.656 INFO 512 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2015-10-10 13:42:41.657 INFO 512 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 10478 ms
2015-10-10 13:42:46.992 INFO 512 --- [ost-startStop-1] o.s.j.d.DriverManagerDataSource : Loaded JDBC driver: com.mysql.jdbc.Driver
2015-10-10 13:42:48.872 INFO 512 --- [ost-startStop-1] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: org.springframework.security.web.util.matcher.AnyRequestMatcher#1, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegration
Filter#390fc764, org.springframework.security.web.context.SecurityContextPersistenceFilter#69bdf685, org.springframework.security.web.header.HeaderWriterFilter#71a70302, org.springframework.security.web.csrf.CsrfFilter#754e07d4, org.springframework.security.web.authentic
ation.logout.LogoutFilter#2eac817e, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#46dea8a1, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#4c69ba89, org.springframework.security.web.servletapi.SecurityContextH
olderAwareRequestFilter#36ac2a3f, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#aa7fb44, org.springframework.security.web.session.SessionManagementFilter#ac2d960, org.springframework.security.web.access.ExceptionTranslationFilter#54bfdd50,
org.springframework.security.web.access.intercept.FilterSecurityInterceptor#1c99fb02]
2015-10-10 13:42:49.358 INFO 512 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2015-10-10 13:42:49.398 INFO 512 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2015-10-10 13:42:49.399 INFO 512 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2015-10-10 13:42:49.399 INFO 512 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2015-10-10 13:42:50.449 INFO 512 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2015-10-10 13:42:50.546 INFO 512 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2015-10-10 13:42:50.913 INFO 512 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {4.3.10.Final}
2015-10-10 13:42:50.941 INFO 512 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2015-10-10 13:42:50.945 INFO 512 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2015-10-10 13:42:51.855 INFO 512 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2015-10-10 13:42:52.080 WARN 512 --- [ main] o.h.e.jdbc.internal.JdbcServicesImpl : HHH000342: Could not obtain connection to query metadata : Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
2015-10-10 13:42:52.095 WARN 512 --- [ 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 exc
eption is org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:747)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
at configuration.Application.main(Application.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:104)
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:71)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:205)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
... 21 common frames omitted
Here is the only thing I change:
#database.driverManagerDataSource.setDriverClassName=com.mysql.jdbc.Driver
#database.driverManagerDataSource.setUrl=jdbc:mysql://localhost:3306/question_time_server
#database.driverManagerDataSource.setUsername=root
#database.driverManagerDataSource.setPassword=
database.driverManagerDataSource.setDriverClassName=com.mysql.jdbc.Driver
database.driverManagerDataSource.setUrl=jdbc:mysql://csrwot1tk8jt.eu-west-1.rds.amazonaws.com:3306/mobilequestionnaire
database.driverManagerDataSource.setUsername=????
database.driverManagerDataSource.setPassword=????
Here is my gradle file:
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE")
classpath 'com.bmuschko:gradle-cargo-plugin:2.1.1'
classpath 'mysql:mysql-connector-java:5.1.16'
classpath 'org.springframework:springloaded:1.2.0.RELEASE'
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
apply plugin: 'war'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'com.bmuschko.cargo'
jar {
baseName = 'MobileQuestionnaire'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework:spring-jdbc:4.1.0.RELEASE")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("mysql:mysql-connector-java:5.1.+")
compile("org.webjars:bootstrap:3.0.3")
compile("org.webjars:jquery:2.0.3-1")
compile("org.springframework.security.oauth:spring-security-oauth2:2.0.7.RELEASE")
testCompile("junit:junit")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
idea {
module {
inheritOutputDirs = false
outputDir = file("$buildDir/classes/main/")
}
}
I thought it would be a simple matter of just pointing from my local to AWS RDS. But it's not...
Any ideas?
I think you are missing the dbinstance before the hash number:
jdbc:mysql://<dbinstance>.csrwot1tk8jt.eu-west-1.rds.amazonaws.com:3306/mobilequestionnaire
I connect to RDS like this (using java config):
// dataSource.setUrl("jdbc:mysql://something.cfscmuq3e7df.us-west-2.rds.amazonaws.com:3306/database");
Also, please check that the elastic beanstalk is configured with the amazon RDS. I no issues building and deploying locally, with my application pointing to the AWS RDS, but once I tried to deploy on the aws elastic beanstalk, i had this issue.
Please look here for a description of how to do it:
Adding an Amazon RDS Database to Your Elastic Beanstalk Environment

Resources