Quarkus #Inject settings from application.properties in #WebFilter - quarkus

I'm trying to #Inject some settings from application.properties in #WebFilter, but it doesn't seem to work:
Caused by: javax.servlet.ServletException: UT010013: Could not instantiate com.foo.www.PageFilter
at io.undertow.servlet.core.ManagedFilter.createFilter(ManagedFilter.java:77)
at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:591)
at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:556)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at io.quarkus.undertow.runtime.UndertowDeploymentRecorder$9$1.call(UndertowDeploymentRecorder.java:566)
at io.undertow.servlet.core.DeploymentManagerImpl.start(DeploymentManagerImpl.java:598)
at io.quarkus.undertow.runtime.UndertowDeploymentRecorder.bootServletContainer(UndertowDeploymentRecorder.java:517)
... 18 more
Caused by: java.lang.RuntimeException: Error injecting com.foo.config.GlobalConfig com.foo.www.PageFilter.globalConfig
at com.foo.www.PageFilter_Bean.create(Unknown Source)
at com.foo.www.PageFilter_Bean.get(Unknown Source)
at com.foo.www.PageFilter_Bean.get(Unknown Source)
The config itself is as follows:
#ConfigMapping(prefix = "global")
public interface GlobalConfig {
List<String> domains();
}
Any workaround?

Related

I tried to connect mysql8.0.32 to the spring boot project in eclipse after I tried to run spring boot main class but its showing some error

Application.properties file
spring.datasource.url=jdbc:mysql://localhost:3306/emp?useSSL=false
spring.datasource.username=root
spring.datasource.password=root
#hibernate properties
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBdialect
#create,create-drop
spring.hibernate.ddl-auto=update
springprojectmain.java
packagePcom.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class StringProject1Application {
public static void main(String[] args) {
SpringApplication.run(StringProject1Application.class, args);
}
}
I got below error:
org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.dialect.MySQL5InnoDBdialect] as strategy [org.hibernate.dialect.Dialect]
at org.hibernate.boot.registry.selector
Caused by: org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [org.hibernate.dialect.MySQL5InnoDBdialect]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:123) ~[hibernate-core-6.1.6.Final.jar:6.1.6.Final]
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:151) ~[hibernate-core-6.1.6.Final.jar:6.1.6.Final]
... 39 common frames omitted
Caused by: java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.dialect.MySQL5InnoDBdialect
at org.hibernate.boot.registry.classloading.internal.AggregatedClassLoader.findClass(AggregatedClassLoader.java:210) ~[hibernate-core-6.1.6.Final.jar:6.1.6.Final]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:587) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[na:na]
at java.base/java.lang.Class.forName0(Native Method) ~[na:na]
at java.base/java.lang.Class.forName(Class.java:467) ~[na:na]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:120) ~[hibernate-core-6.1.6.Final.jar:6.1.6.Final]
... 40 common frames omitted
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1751) ~[spring-beans-6.0.4.jar:6.0.4]
at org.springframework.beans.factory.
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:267) ~[hibernate-core-6.1.6.Final.jar:6.1.6.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:230) ~[hibernate-core-6.1.6.Final.jar:6.1.6.Final]
at org.hibernate.service.
I tried to connect mysql8.0.32 to the spring boot project in eclipse after I tried to run spring boot main class but its showing some error in application properties file at spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBdialect.
In the following line:
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBdialect
Replace MySQL5InnoDBdialect with MySQL5Dialect.

Trouble configuring spring caffeine cache manager

I have a spring boot project which serves as a library (packaged jar file) to some other project. I am trying yo configure caffeine cache that will refresh asynchronously after request is made to the service.
pom.xml (includes) :
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
My configuration class :
#EnableCaching
#Configuration
public class CaffeineCacheConfig {
#Bean
public CacheManager cacheManager(){
CaffeineCacheManager cacheManager = new CaffeineCacheManager("userStories", "features");
cacheManager.setCaffeine(caffeineCacheBuilder());
cacheManager.setAllowNullValues(false);
return cacheManager;
}
Caffeine<Object, Object> caffeineCacheBuilder() {
return Caffeine.newBuilder()
.initialCapacity(100)
.maximumSize(500)
.refreshAfterWrite(1, TimeUnit.MINUTES)
.weakKeys()
.recordStats();
}
}
DAO layer (needs caching here) :
#Component
#EnableCaching
#CacheConfig(cacheNames = {"userStories"})
public class UserStoryDaoImpl implements IUserStoryDao {
#Override
#Cacheable
public List<UserStory> getUserStoriesForProjectAndRelease(UserDto userDto, Set<Integer> reportProjectId, int releaseId) {
return new ArrayList(); //slow and low performing method that returns a list
}
DAO layer (needs caching here as well) :
#Component
#EnableCaching
#CacheConfig(cacheNames = {"features"})
public class FeatureDaoImpl implements IFeatureDao {
#Override
#Cacheable
public List<Features> geFeaturesForProjectAndRelease(UserDto userDto, Set<Integer> reportProjectId, int releaseId) {
return new ArrayList(); //slow and low performing method that returns a list
}
}
I am getting below error stack while running this setup:
2020-03-31 16:55:46,020 ERROR web.context.ContextLoader - Context initialization failed [localhost-startStop-1] {}
java.lang.NullPointerException
at org.springframework.context.annotation.AutoProxyRegistrar.registerBeanDefinitions(AutoProxyRegistrar.java:62)
at org.springframework.context.annotation.ConfigurationClassParser.processImport(ConfigurationClassParser.java:385)
at org.springframework.context.annotation.ConfigurationClassParser.processImport(ConfigurationClassParser.java:377)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:205)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:164)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:130)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:287)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:225)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:632)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at com.intland.codebeamer.context.CodeBeamerContextListener.lambda$contextInitialized$1(CodeBeamerContextListener.java:117)
at com.intland.codebeamer.context.CodeBeamerContextListener.logExecutionTime(CodeBeamerContextListener.java:148)
at com.intland.codebeamer.context.CodeBeamerContextListener.contextInitialized(CodeBeamerContextListener.java:117)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4699)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5165)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1125)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1859)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
2020-03-31 16:55:46,070 INFO codebeamer.context.CodeBeamerContextListener - Context - Destroyed [localhost-startStop-1] {}
2020-03-31 16:55:46,132 WARN context.support.XmlWebApplicationContext - Exception thrown from ApplicationListener handling ContextClosedEvent [localhost-startStop-1] {}
java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: Root WebApplicationContext: startup date [Tue Mar 31 16:55:35 IST 2020]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:347)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:334)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1051)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1012)
at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:586)
at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:143)
at com.intland.codebeamer.context.CodeBeamerContextListener.contextDestroyed(CodeBeamerContextListener.java:128)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4746)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5403)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:226)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1125)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1859)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
2020-03-31 16:55:46,132 WARN context.support.XmlWebApplicationContext - Exception thrown from LifecycleProcessor on context close [localhost-startStop-1] {}
java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: Root WebApplicationContext: startup date [Tue Mar 31 16:55:35 IST 2020]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:360)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1059)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1012)
at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:586)
at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:143)
at com.intland.codebeamer.context.CodeBeamerContextListener.contextDestroyed(CodeBeamerContextListener.java:128)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4746)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5403)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:226)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1125)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1859)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Not sure what is missing in the setup?
Start with removing #EnableCaching from #Component classes - keep
it only on #Configuration.
Not sure about #CacheConfig, normally
you can configure cache name in #Cacheable.
I have previous experience with your idea. The problem here is that refreshing cache needs a method to do the refresh - a method which would produce an up-to-date value based on the key. It's tricky to implement such method when key is based on multiple parameters from the method signature. Also this means that value loading mechanism should be implemented twice: in the annotated method and in the reloader.
I have fixed it to add the next line to the application properties:
cache.ttl=60

spring boot build errors with Error creating bean with name 'entityManagerFactory' defined

I am using two datasources in my spring boot (1.4.RELEASE) application. when I run the gradle build (./gradlew clean build), it fails in test task with following error:
com.company.foo.ApplicationTests > contextLoads FAILED
java.lang.IllegalStateException
Caused by: org.springframework.beans.factory.BeanCreationException
Caused by: org.hibernate.service.spi.ServiceException
Caused by: org.hibernate.HibernateException
error with stack-trace is available below after the code samples
NOTE: if I comment out the code, in ApplicationTests and run the build, it is successful. when I start the application java -jar "myApp.jar", the application starts fine and retrives data from both datasources. so it is definitely something wrong in the test configuration that is causing build failure.
src/main/resources/application.properties
#datasource
spring.datasource.username=admin
spring.datasource.url=jdbc:mysql://localhost:3306/user_table
spring.datasource.password=dsdfdfdsfeddf
spring.datasource.tomcat.max-wait=10000
spring.datasource.tomcat.max-active=100
spring.datasource.tomcat.min-idle=10
spring.datasource.tomcat.test-on-borrow=true
spring.datasource.tomcat.validation-query=select 1
spring.datasource.tomcat.remove-abandoned=true
#SQL SERVER Datasource
spring.ms.datasource.username=gogtou
spring.ms.datasource.url=jdbc:jtds:sqlserver://localhost:1433/company_table;
spring.ms.datasource.password=adfdfds
spring.ms.datasource.tomcat.max-wait=10000
spring.ms.datasource.tomcat.max-active=100
spring.ms.datasource.tomcat.min-idle=10
spring.ms.datasource.tomcat.test-on-borrow=true
spring.ms.datasource.tomcat.validation-query=select 1
spring.ms.datasource.tomcat.remove-abandoned=true
src/main/java/com/company/foo/config/DBConfig.java
#Configuration
public class DBConfig {
#Bean(name="myDataSource")
#Primary
#ConfigurationProperties(prefix="spring.datasource")
public DataSource myDataSource() {
return DataSourceBuilder.create().build();
}
#Bean(name = "MsDataSource")
#ConfigurationProperties(prefix="spring.ms.datasource")
public DataSource msDataSource() {
return DataSourceBuilder.create().build();
}
#Bean(name = "jdbcmyTemplate")
#Autowired
public JdbcTemplate jdbcmyTemplate(#Qualifier("myDataSource") DataSource ds) {
return new JdbcTemplate(ds);
}
#Bean(name = "jdbcmyNamedTemplate")
#Autowired
public NamedParameterJdbcTemplate jdbcmyNamedTemplate(#Qualifier("myDataSource") DataSource ds) {
return new NamedParameterJdbcTemplate(ds);
}
#Bean(name = "jdbcMsTemplate")
#Autowired
public JdbcTemplate jdbcMsTemplate(#Qualifier("MsDataSource") DataSource hanaDataSource) {
return new JdbcTemplate(MsDataSource);
}
}
src/main/java/com/company/foo/Application.java
#SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
src/test/java/com/company/foo/ApplicationTests.java
#RunWith(SpringRunner.class)
#SpringBootTest
#WebAppConfiguration
public class ApplicationTests {
#Test
public void contextLoads() {
System.out.println("test passed");
}
}
ERROR
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:189)
at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:131)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:112)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:56)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:66)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
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 org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:109)
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 org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:364)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: 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 org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1076)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:851)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:111)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
... 45 more
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:244)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:208)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:847)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:874)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:338)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
... 60 more
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:100)
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:234)
... 76 more
PS I have read other posts in SO with similar errors. but the issue here is different
I found the problem. I am using spring-data-jpa and it requires to configure datasources, entityManagerFactory manually in case of two datasources. In my case, I simply removed Spring-data-dependency and the build was successful. If you still want to use spring-data-jpa, here is example of how to configure two datasources manually.
On my case, the error was because the connections to database were incorrect, that is
-database
-username
-password.
Ensure they are all correct
Try to add hsqldb dependency to your project.
Jens

Add another PropertyResourceConfigurer programatically with spring-boot

We're setting up an advanced/complex multimodule build with gradle, groovy and spring-boot.
In addition to using #EnableAutoConfiguration to automatically pick up application*.yml files, we would like to register a "custom" PropertyResourceConfigurer to handle common properties placed in a separate "config" module which can be reused across several spring- boot apps.
However, when adding the following in a #Configuration annotated class, startup fails with an exception
#Configuration
class CommonConfig {
#Autowired
Environment env;
#Bean (name = 'geit')
PropertyResourceConfigurer geitProperties() {
PropertyResourceConfigurer configurer = new PropertyPlaceholderConfigurer();
Resource[] resources = new Resource[env.activeProfiles.length];
println "Environment2 : ${env}"
env.activeProfiles.eachWithIndex() {
env, i -> resources[i] = new UrlResource(getURL(String.format("classpath:environment/%s.properties", env)))
}
configurer.setLocations(resources)
return configurer
}
}
the exception is
4fa8a851930816b4d09ecb1/springloaded-1.2.1.RELEASE.jar]
at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:57)
2014-11-04 14:13:56.975 ERROR 48941 --- [ main] o.s.boot.SpringApplication : Application startup failed
at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:168)
at org.codehaus.groovy.runtime.callsite.NullCallSite.getProperty(NullCallSite.java:44)
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'geit' defined in class path resource [geit/config/CommonConfig.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.beans.factory.config.PropertyResourceConfigurer geit.config.CommonConfig.geitProperties()] threw exception; nested exception is java.lang.NullPointerException: Cannot get property 'activeProfiles' on null object
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:227)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:601)
at geit.config.CommonConfig.geitProperties(CommonConfig.groovy:55)
at geit.config.CommonConfig$$EnhancerBySpringCGLIB$$c13414af.CGLIB$geitProperties$21(<generated>)
at geit.config.CommonConfig$$EnhancerBySpringCGLIB$$c13414af$$FastClassBySpringCGLIB$$e7b06e5c.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1113)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:312)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFaat geit.config.CommonConfig$$EnhancerBySpringCGLIB$$c13414af.geitProperties(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
ry.java:1008)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:505)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1270)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
... 22 more
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:150)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:692)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:322)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:962)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:951)
at org.springframework.boot.SpringApplication$run.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
at geit.AdminApplication.main(AdminApplication.groovy:19)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.beans.factory.config.PropertyResourceConfigurer geit.config.CommonConfig.geitProperties()] threw exception; nested exception is java.lang.NullPointerException: Cannot get property 'activeProfiles' on null object
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:188)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:590)
... 21 common frames omitted
Caused by: java.lang.NullPointerException: Cannot get property 'activeProfiles' on null object
at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:57)
at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:168)
at org.codehaus.groovy.runtime.callsite.NullCallSite.getProperty(NullCallSite.java:44)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:227)
at geit.config.CommonConfig.geitProperties(CommonConfig.groovy:55)
at geit.config.CommonConfig$$EnhancerBySpringCGLIB$$c13414af.CGLIB$geitProperties$21(<generated>)
at geit.config.CommonConfig$$EnhancerBySpringCGLIB$$c13414af$$FastClassBySpringCGLIB$$e7b06e5c.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:312)
at geit.config.CommonConfig$$EnhancerBySpringCGLIB$$c13414af.geitProperties(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1270)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.iate(SimpleInstantiationStrategy.java:166)
... 22 common frames omitted
However, when adding the following to CommonConfig
#Bean
public String profileConfigBean() {
println "Environment : ${env}"
env.activeProfiles.each {
println it
}
'devprofilebean'
}
this correctly prints all active profiles.
Even adding an empty PropertyResourceConfigurer causes startup to fail
Found a working solution.
I added a class annotated with #PropertySource for each environment pluss one for default properties.
examples:
One for DEV
#Configuration
#Profile(Profiles.DEV)
#PropertySource("classpath:/environment/dev.properties")
class CommonDevConfig {
}
and the one for default
#Configuration
#PropertySource("classpath:/environment/default.properties")
class CommonConfig {
}

Jboss error on deployment bean

I'm trying to deploy a bean that uses #Interceptros annotation in Jboss.
According to documentation I've created beanRefContext.xml and here is Bean code
#Stateless
#LocalBean
#Interceptors(SpringBeanAutowiringInterceptor.class)
public class ClienteBean implements ClienteBeanLocal {
public ClienteBean() {
// TODO Auto-generated constructor stub
}
#Autowired
private IClienteDAO cliente;
#Override
public List<ClienteDTO> selectALL() throws Exception {
return cliente.selectALL();
}
}
I am deploying it inside an EAR. When I try to deploy in Jboss 6 I get the following error:
Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
at sun.reflect.annotation.AnnotationParser.parseClassArray(Unknown Source) [:1.7.0_09]
at sun.reflect.annotation.AnnotationParser.parseArray(Unknown Source) [:1.7.0_09]
at sun.reflect.annotation.AnnotationParser.parseMemberValue(Unknown Source) [:1.7.0_09]
at sun.reflect.annotation.AnnotationParser.parseAnnotation(Unknown Source) [:1.7.0_09]
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(Unknown Source) [:1.7.0_09]
at sun.reflect.annotation.AnnotationParser.parseAnnotations(Unknown Source) [:1.7.0_09]
at java.lang.Class.initAnnotationsIfNecessary(Unknown Source) [:1.7.0_09]
at java.lang.Class.getAnnotations(Unknown Source) [:1.7.0_09]
at org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactoryImpl.readAnnotations(IntrospectionTypeInfoFactoryImpl.java:610) [jboss-reflect.jar:2.2.0.GA]
at org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactoryImpl.getAnnotations(IntrospectionTypeInfoFactoryImpl.java:126) [jboss-reflect.jar:2.2.0.GA]
at org.jboss.reflect.plugins.InheritableAnnotationHolder.getDeclaredAnnotations(InheritableAnnotationHolder.java:96) [jboss-reflect.jar:2.2.0.GA]
at org.jboss.reflect.plugins.ClassInfoImpl.getAnnotations(ClassInfoImpl.java:181) [jboss-reflect.jar:2.2.0.GA]
at org.jboss.reflect.plugins.AbstractAnnotatedInfo.getUnderlyingAnnotations(AbstractAnnotatedInfo.java:63) [jboss-reflect.jar:2.2.0.GA]
at org.jboss.scanning.plugins.visitor.ClassHierarchyResourceVisitor.handleClass(ClassHierarchyResourceVisitor.java:76) [:1.0.0.GA]
at org.jboss.scanning.plugins.visitor.ReflectResourceVisitor.doVisit(ReflectResourceVisitor.java:108) [:1.0.0.GA]
at org.jboss.scanning.plugins.visitor.ReflectResourceVisitor.visit(ReflectResourceVisitor.java:86) [:1.0.0.GA]
... 53 more
How can I solve it?
Seems JBoss is not seeing SpringBeanAutowiringInterceptor.class. In your EAR file put your spring jars on the lib directory. See if that works.
If you are using maven to assemble your EAR file you can do something like this:
http://maven.apache.org/plugins/maven-ear-plugin/examples/customizing-module-location.html

Resources