H2: JdbcSQLException: URL format error - java

I replaced a configuration which makes a connection to real database with another configuration that should make a connection to in-memory database. I want to use this configuration for integration testing. A simple test looks like this
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
#RunWith(SpringRunner.class)
#SpringBootTest
public class WebApplicationTests {
#Test
public void contextLoads() {}
}
New configuration in pom.xml
<profiles>
<profile>
<id>IntegrationTest</id>
<properties>
<datasource.url>jdbc:h2:mem:db_name_test;MODE=MSSQLServer;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS db_name_test\\;SET SCHEMA db_name_test</datasource.url>
<datasource.username>sa</datasource.username>
<datasource.password></datasource.password>
</properties>
</profile>
<!-- other profiles omitted -->
</profiles>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.195</version>
</dependency>
<!-- some dependencies omitted -->
</dependencies>
These properties are injected in resource files and later picked up by Spring during context initialization. Data Source configuration in XML context looks like:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="url" value="${datasource.url}"/>
<property name="username" value="${datasource.username}"/>
<property name="password" value="${datasource.password}"/>
</bean>
I use this command to build the project and perform testing:
mvn -T 1C clean integration-test -P IntegrationTest
The test which worked with previous configuration now throws the below exception.
Stacktrace
2018-03-13 13:36:04.627 ERROR 9076 --- [ main] o.s.test.context.TestContextManager : Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener#cb6c1e9] to prepare test instance [com.WebApplicationTests#3d52aca]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) ~[spring-test-4.3.14.RELEASE.jar:4.3.14.RELEASE]
... some frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'aService': Unsatisfied dependency expressed through field 'ctSecurityUtils'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ctSecurityUtils': Unsatisfied dependency expressed through field 'arService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'arService': Invocation of init method failed; nested exception is org.springframework.orm.jpa.JpaSystemException: Unable to acquire JDBC Connection; nested exception is org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
... some frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ctSecurityUtils': Unsatisfied dependency expressed through field 'arService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'arService': Invocation of init method failed; nested exception is org.springframework.orm.jpa.JpaSystemException: Unable to acquire JDBC Connection; nested exception is org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
... some frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'arService': Invocation of init method failed; nested exception is org.springframework.orm.jpa.JpaSystemException: Unable to acquire JDBC Connection; nested exception is org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:137) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
... some frames omitted
Caused by: org.springframework.orm.jpa.JpaSystemException: Unable to acquire JDBC Connection; nested exception is org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:333) ~[spring-orm-4.3.14.RELEASE.jar:4.3.14.RELEASE]
... some frames omitted
Caused by: org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
... some frames omitted
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (URL format error; must be "jdbc:h2:{ {.|mem:}[name] | [file:]fileName | {tcp|ssl}:[//]server[:port][,server2[:port]]/name }[;key=value...]" but is "jdbc:h2:mem:db_name_test" [90046-196])
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549) ~[commons-dbcp-1.4.jar:1.4]
... some frames omitted
Caused by: org.h2.jdbc.JdbcSQLException: URL format error; must be "jdbc:h2:{ {.|mem:}[name] | [file:]fileName | {tcp|ssl}:[//]server[:port][,server2[:port]]/name }[;key=value...]" but is "jdbc:h2:mem:db_name_test" [90046-196]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345) ~[h2-1.4.196.jar:1.4.196]
... some frames omitted
How to fix it?

By the trial and error method I've found that this statement in the connection string is causing the error
\\;SET SCHEMA db_name_test
There's no JdbcSQLException: URL format error exception when it's removed. But I wanted to preserve an application behaviour so instead of deleting the statement I moved it into connectionInitSqls. Also I've specified driverClassName.
Updated Maven profile:
<profile>
<id>IntegrationTest</id>
<properties>
<datasource.driverClassName>org.h2.Driver</datasource.driverClassName>
<datasource.url>jdbc:h2:mem:db_name_test;MODE=MSSQLServer;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS db_name_test</datasource.url>
<datasource.connectionInitSqls>SET SCHEMA db_name_test</datasource.connectionInitSqls>
<datasource.username>sa</datasource.username>
<datasource.password></datasource.password>
</properties>
</profile>
Updated Data Source configuration in XML context:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${datasource.driverClassName}"/>
<property name="url" value="${datasource.url}"/>
<property name="username" value="${datasource.username}"/>
<property name="password" value="${datasource.password}"/>
<property name="connectionInitSqls" value="${datasource.connectionInitSqls}"/>
</bean>

Related

Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#31' while setting bean property 'sourceList' with key

Recently, I have upgraded to Spring 5.3.20 from 4.0.5.RELEASE and I have changed the other dependencies versions also. It is getting successfully build, but when I try to run, it is giving error after jetty.
Upgraded versions in Pom.xml:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java-version>1.8</java-version>
<org.springframework-version>5.3.20</org.springframework-version>
<org.springframework-security-version>5.6.3</org.springframework-security-version>
<org.apache.tiles-version>3.0.4</org.apache.tiles-version>
<!-- <org.hibernate-version>5.6.10.Final</org.hibernate-version> --> <!-- 4.3.5.Final -->
<org.hibernate-version>5.3.7.Final</org.hibernate-version><!-- 5.1.17.Final -->
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.7.7</org.slf4j-version>
<jackson.version>2.11.3</jackson.version> <!-- 2.11.3 -->
<!-- <jackson.version>2.14.1</jackson.version> -->
</properties>
The build is successful (using maven) but when I try to run the code I am getting this error after jetty,
Error -
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains': Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#31' while setting bean property 'sourceList' with key [31];
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#31': Cannot resolve reference to bean 'concurrencyFilter' while setting constructor argument with key [2];
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'concurrencyFilter' defined in ServletContext resource [/WEB-INF/spring/security.xml]: Instantiation of bean failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.web.session.ConcurrentSessionFilter]: No default constructor found;
nested exception is java.lang.NoSuchMethodException: org.springframework.security.web.session.ConcurrentSessionFilter.<init>()
Can anybody help me to resolve this error. Would really appreciate any help.

spring boot mongodb connection error

i try to connect my spring boot application to mongodb, but i get a connection error with the driver class. Here a part of code.
my pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.1.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
</dependency>
</dependencies>
My main class:
#SpringBootApplication
#EnableAutoConfiguration
#ComponentScan("XXXX")
public class TestClass extends SpringBootServletInitializer{
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(TestClass.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(TestClass.class, args);
}
}
my properties file:
spring.data.mongodb.uri=jdbc:mongodb://localhost:27017/test
spring.datasource.driver-class-name=mongodb.jdbc.MongoDriver
a part of a log:
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: mongodb.jdbc.MongoDriver
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 32 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: mongodb.jdbc.MongoDriver
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
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.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
... 34 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: mongodb.jdbc.MongoDriver
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 46 more
Caused by: java.lang.IllegalStateException: Cannot load driver class: mongodb.jdbc.MongoDriver
at org.springframework.util.Assert.state(Assert.java:392)
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.getDriverClassName(DataSourceProperties.java:165)
at org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.dataSource(DataSourceAutoConfiguration.java:120)
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:497)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 47 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Any ideas about this problem? What is wrong in my project? Can someone help me?
Thanks for helping.
Cheers
If you really want to use MongoDB with JDBC, you can use UnityJDBC. Follow these steps to add the library to your application: http://www.unityjdbc.com/mongojdbc/mongo_jdbc.php
I suggest you to follow this guide to access MongoDB data without a JDBC driver: https://spring.io/guides/gs/accessing-data-mongodb/

Error while deploying Spring Batch in Weblogic BeanCreationException: Error creating bean with name 'jobRepository'

I want to test Spring Batch, but I need to use it without maven or gradle because there are some restrictions in the network. I read a tutorial on spring and the spring documentation to configure a Job, but I get an "Error creating bean with name 'jobRepository'"
This question has been asked already without an answer.
I'm using Jeveloper and Weblogic 12.1.3.0.0.
My project has the following dependencies which I get from another project configured with Eclipse Maven:
com.ibm.jbatch-tck-spi-1.0.jar
commons-logging-1.2.jar
hsqldb-2.3.3.jar
javax.batch-api-1.0.jar
jcl-over-slf4j-1.7.12.jar
jettison-1.2.jar
jul-to-slf4j-1.7.12.jar
log4j-over-slf4j-1.7.12.jar
logback-classic-1.1.3.jar
logback-core-1.1.3.jar
slf4j-api-1.7.12.jar
snakeyaml-1.14.jar
spring-aop-4.1.8.RELEASE.jar
spring-aspects-4.1.8.RELEASE.jar
spring-batch-core-3.0.5.RELEASE.jar
spring-batch-infrastructure-3.0.5.RELEASE.j
spring-beans-4.1.8.RELEASE.jar
spring-context-4.1.8.RELEASE.jar
spring-context-support-4.1.8.RELEASE.jar
spring-core-4.1.8.RELEASE.jar
spring-expression-4.1.8.RELEASE.jar
spring-instrument-4.1.8.RELEASE.jar
spring-instrument-tomcat-4.1.8.RELEASE.jar
spring-jdbc-4.1.8.RELEASE.jar
spring-jms-4.1.8.RELEASE.jar
spring-messaging-4.1.8.RELEASE.jar
spring-orm-4.1.8.RELEASE.jar
spring-oxm-4.1.8.RELEASE.jar
spring-test-4.1.8.RELEASE.jar
spring-tx-4.1.8.RELEASE.jar
spring-web-4.1.8.RELEASE.jar
spring-webmvc-4.1.8.RELEASE.jar
spring-webmvc-portlet-4.1.8.RELEASE.jar
spring-websocket-4.1.8.RELEASE.jar
xmlpull-1.1.3.1.jar
xpp3_min-1.1.4c.jar
xstream-1.4.7.jar
The java classes are:
JobLauncherController.java
package batch;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class JobLauncherController {
#Autowired
JobLauncher jobLauncher;
#Autowired
Job job;
#RequestMapping("/jobLauncher.html")
public String handle() throws Exception{
System.err.println("Hello Spring Batch!");
jobLauncher.run(job, new JobParameters());
return "redirect:index";
}
}
MyTasklet.java
package batch;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
public class MyTasklet implements Tasklet{
#Override
public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
System.err.println("¡Hello World TASKLET!");
return RepeatStatus.FINISHED;
}
}
web.xml
<?xml version = '1.0' encoding = 'windows-1252'?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Test Batch App</display-name>
<servlet>
<servlet-name>testBatch</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>testBatch</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<jsp-config>
<taglib>
<taglib-uri>http://www.springframework.org/tags/form</taglib-uri>
<taglib-location>/WEB-INF/spring-form.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
testBatch-servlet.xml
<beans:beans xmlns="http://www.springframework.org/schema/batch"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="batch"/>
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/"/>
<beans:property name="suffix" value=".jsp"/>
</beans:bean>
<beans:bean id="transactionManager"
class="org.springframework.batch.support.transaction.ResourcelessTransactionManager"></beans:bean>
<beans:bean id="jobRepository"
class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
<beans:property name="transactionManager" ref="transactionManager"/>
</beans:bean>
<beans:bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<beans:property name="jobRepository" ref="jobRepository"/>
<beans:property name="taskExecutor">
<beans:bean class="org.springframework.core.task.SimpleAsyncTaskExecutor"/>
</beans:property>
</beans:bean>
<beans:bean id="myTasklet" class="batch.MyTasklet"></beans:bean>
<job id="job">
<step id="test">
<tasklet ref="myTasklet"/>
</step>
</job>
</beans:beans>
And last but not least, the stacktrace
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobLauncherController': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.springframework.batch.core.launch.JobLauncher batch.JobLauncherController.jobLauncher; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobLauncher' defined in ServletContext resource [/WEB-INF/testBatch-servlet.xml]: Cannot resolve reference to bean 'jobRepository' while setting bean property 'jobRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobRepository' defined in ServletContext resource [/WEB-INF/testBatch-servlet.xml]: Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation(AutowiredAnnotationBeanPostProcessor.java:243)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:959)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeweblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$100(DeploymentReceiverCallbackDeliverer.java:13)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$2.run(DeploymentReceiverCallbackDeliverer.java:68)
at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:548)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:311)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:263)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.springframework.batch.core.launch.JobLauncher batch.JobLauncherController.jobLauncher; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobLauncher' defined in ServletContext resource [/WEB-INF/testBatch-servlet.xml]: Cannot resolve reference to bean 'jobRepository' while setting bean property 'jobRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobRepository' defined in ServletContext resource [/WEB-INF/testBatch-servlet.xml]: Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:435)
at org.springframework.beans.factory.annotation.InjectionMetadata.injectFields(InjectionMetadata.java:105)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation(AutowiredAnnotationBeanPostProcessor.java:240)
... 66 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobLauncher' defined in ServletContext resource [/WEB-INF/testBatch-servlet.xml]: Cannot resolve reference to bean 'jobRepository' while setting bean property 'jobRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobRepository' defined in ServletContext resource [/WEB-INF/testBatch-servlet.xml]: Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:671)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:610)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:412)
... 68 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobRepository' defined in ServletContext resource [/WEB-INF/testBatch-servlet.xml]: Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
... 83 more
Caused by: java.lang.reflect.MalformedParameterizedTypeException
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(ParameterizedTypeImpl.java:60)
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.<init>(ParameterizedTypeImpl.java:53)
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(ParameterizedTypeImpl.java:95)
at sun.reflect.generics.factory.CoreReflectionFactory.makeParameterizedType(CoreReflectionFactory.java:105)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:140)
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
at sun.reflect.generics.repository.ClassRepository.getSuperInterfaces(ClassRepository.java:100)
at java.lang.Class.getGenericInterfaces(Class.java:814)
at org.springframework.core.GenericTypeResolver.getTypeVariableMap(GenericTypeResolver.java:164)
at org.springframework.core.GenericTypeResolver.resolveReturnType(GenericTypeResolver.java:101)
at org.springframework.beans.GenericTypeAwarePropertyDescriptor.getPropertyType(GenericTypeAwarePropertyDescriptor.java:88)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1289)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1250)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
... 92 more
<21/10/2015 02:01:45 AM COT> <Error> <HTTP> <BEA-101216> <Servlet: "testBatch" failed to preload on startup in Web application: "testBatch".
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobLauncherController': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.springframework.batch.core.launch.JobLauncher batch.JobLauncherController.jobLauncher; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobLauncher' defined in ServletContext resource [/WEB-INF/testBatch-servlet.xml]: Cannot resolve reference to bean 'jobRepository' while setting bean property 'jobRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobRepository' defined in ServletContext resource [/WEB-INF/testBatch-servlet.xml]: Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation(AutowiredAnnotationBeanPostProcessor.java:243)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:959)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
Truncated. see log file for complete stacktrace
Caused By: org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.springframework.batch.core.launch.JobLauncher batch.JobLauncherController.jobLauncher; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobLauncher' defined in ServletContext resource [/WEB-INF/testBatch-servlet.xml]: Cannot resolve reference to bean 'jobRepository' while setting bean property 'jobRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobRepository' defined in ServletContext resource [/WEB-INF/testBatch-servlet.xml]: Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:435)
at org.springframework.beans.factory.annotation.InjectionMetadata.injectFields(InjectionMetadata.java:105)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation(AutowiredAnnotationBeanPostProcessor.java:240)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:959)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
Truncated. see log file for complete stacktrace
Caused By: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobLauncher' defined in ServletContext resource [/WEB-INF/testBatch-servlet.xml]: Cannot resolve reference to bean 'jobRepository' while setting bean property 'jobRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobRepository' defined in ServletContext resource [/WEB-INF/testBatch-servlet.xml]: Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
Truncated. see log file for complete stacktrace
Caused By: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobRepository' defined in ServletContext resource [/WEB-INF/testBatch-servlet.xml]: Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
Truncated. see log file for complete stacktrace
Caused By: java.lang.reflect.MalformedParameterizedTypeException
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(ParameterizedTypeImpl.java:60)
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.<init>(ParameterizedTypeImpl.java:53)
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(ParameterizedTypeImpl.java:95)
at sun.reflect.generics.factory.CoreReflectionFactory.makeParameterizedType(CoreReflectionFactory.java:105)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:140)
Truncated. see log file for complete stacktrace
>
WARN: The method class org.apache.commons.logging.impl.SLF4JLogFactory#release() was invoked.
WARN: Please see http://www.slf4j.org/codes.html#release for an explanation.
<21/10/2015 02:01:45 AM COT> <Error> <Deployer> <BEA-149265> <Failure occurred in the execution of deployment request with ID "32136025790510" for task "15". Error is: "weblogic.application.ModuleException: java.lang.reflect.MalformedParameterizedTypeException"
weblogic.application.ModuleException: java.lang.reflect.MalformedParameterizedTypeException
at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)
at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:216)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:211)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
Truncated. see log file for complete stacktrace
Caused By: java.lang.reflect.MalformedParameterizedTypeException
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(ParameterizedTypeImpl.java:60)
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.<init>(ParameterizedTypeImpl.java:53)
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(ParameterizedTypeImpl.java:95)
at sun.reflect.generics.factory.CoreReflectionFactory.makeParameterizedType(CoreReflectionFactory.java:105)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:140)
Truncated. see log file for complete stacktrace
>
<21/10/2015 02:01:45 AM COT> <Error> <Deployer> <BEA-149202> <Encountered an exception while attempting to commit the 9 task for the application "TestBatch".>
<21/10/2015 02:01:45 AM COT> <Warning> <Deployer> <BEA-149004> <Failures were detected while initiating deploy task for application "TestBatch".>
<21/10/2015 02:01:45 AM COT> <Warning> <Deployer> <BEA-149078> <Stack trace for message 149004
weblogic.application.ModuleException: java.lang.reflect.MalformedParameterizedTypeException
at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)
at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:216)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:211)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
Truncated. see log file for complete stacktrace
Caused By: java.lang.reflect.MalformedParameterizedTypeException
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(ParameterizedTypeImpl.java:60)
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.<init>(ParameterizedTypeImpl.java:53)
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(ParameterizedTypeImpl.java:95)
at
Any suggestion will be appreciated, thanks in advance.
UPDATE
I think is something related to Weblogic 12.1.3.0(12c). I made a web project in Netbeans (with and without Maven), and these work fine. Maybe Weblogic requires some special configuration?
the following jars were generated with netbeans and maven (spring-batch-core, 3.0.5.RELEASE and spring-webmvc, 4.0.5.RELEASE) as Malguna said
aopalliance-1.0.jar
com.ibm.jbatch-tck-spi-1.0.jar
commons-logging-1.1.3.jar
javax.batch-api-1.0.jar
jettison-1.2.jar
spring-aop-4.0.5.RELEASE.jar
spring-batch-core-3.0.5.RELEASE.jar
spring-batch-infrastructure-3.0.5.RELEASE.jar
spring-beans-4.0.5.RELEASE.jar
spring-context-4.0.5.RELEASE.jar
spring-core-4.0.5.RELEASE.jar
spring-expression-4.0.5.RELEASE.jar
spring-retry-1.1.0.RELEASE.jar
spring-tx-4.0.5.RELEASE.jar
spring-web-4.0.5.RELEASE.jar
spring-webmvc-4.0.5.RELEASE.jar
xmlpull-1.1.3.1.jar
xpp3_min-1.1.4c.jar
xstream-1.4.7.jar
UPDATE II
I made a workaround to this issue, although It doesn't tackle the real problem It let me keep forward in what I really want. That is, making Jdeveloper (12c), Weblogic and Spring Batch work together.
I add a jobRepository and a datasource whit hsqldb in the testBatch-servlet.xml. After that, add hsqldb-2.3.3.jar and spring-jdbc-4.0.5.RELEASE.jar
<beans:bean id="jobRepository" class="org.springframework.batch.core.repository.support.SimpleJobRepository">
<beans:constructor-arg>
<beans:bean class="org.springframework.batch.core.repository.dao.MapJobInstanceDao"/>
</beans:constructor-arg>
<beans:constructor-arg>
<beans:bean class="org.springframework.batch.core.repository.dao.MapJobExecutionDao" />
</beans:constructor-arg>
<beans:constructor-arg>
<beans:bean class="org.springframework.batch.core.repository.dao.MapStepExecutionDao"/>
</beans:constructor-arg>
<beans:constructor-arg> <!-- Extra constructor argument -->
<beans:bean class="org.springframework.batch.core.repository.dao.MapExecutionContextDao"/>
</beans:constructor-arg>
</beans:bean>
If you get an java.lang.reflect.MalformedParameterizedTypeException this means there are some class that is trying to use a method by means of reflection, but it has malformed the parameters needed to call it.
This is common when you have wrong dependencies, that is, when you are using wrong dependency version and thus a dependent method has changed its parameters list.
I created a void pom.xml with only spring-batch-core version 3.0.5.RELEASE and it gives me the following dependencies list:
aopalliance-1.0.jar
com.ibm.jbatch-tck-spi-1.0.jar
commons-logging-1.1.3.jar
javax.batch-api-1.0.jar
jettison-1.2.jar
spring-aop-4.0.5.RELEASE.jar
spring-batch-core-3.0.5.RELEASE.jar
spring-batch-infrastructure-3.0.5.RELEASE.jar
spring-beans-4.0.5.RELEASE.jar
spring-context-4.0.5.RELEASE.jar
spring-core-4.0.5.RELEASE.jar
spring-expression-4.0.5.RELEASE.jar
spring-retry-1.1.0.RELEASE.jar
spring-tx-4.0.5.RELEASE.jar
xmlpull-1.1.3.1.jar
xpp3_min-1.1.4c.jar
xstream-1.4.7.jar
So as you can see, you are using spring version 4.1.8.RELEASE instead 4.0.5.RELEASE. This could be the cause of your error.
Please review your hand managed dependencies to fit those I shown you. Maybe it resolves your problem.
Hope it helps!
To solve the problem I need to use Spring Batch 2.2.7 together with Weblogic 12.1.3.
I thought that The error was configuration in my xml file but It seems that is a support issue with weblogic, because I found a similar error later.
The dependency list:
aopalliance-1.0.jar
commons-logging-1.1.3.jar
jettison-1.1.jar
spring-aop-3.2.9.RELEASE.jar
spring-batch-core-2.2.7.RELEASE.jar
spring-batch-infrastructure-2.2.7.RELEASE.jar
spring-beans-3.2.9.RELEASE.jar
spring-context-3.2.9.RELEASE.jar
spring-core-3.2.9.RELEASE.jar
spring-expression-3.2.9.RELEASE.jar
spring-retry-1.0.2.RELEASE.jar
spring-tx-3.2.9.RELEASE.jar
spring-web-3.2.9.RELEASE.jar
spring-webmvc-3.2.9.RELEASE.jar
xpp3_min-1.1.4c.jar
xstream-1.3.jar

No lookup on start for datasources in hibernate multi-tenant application

I am currently working on a multi-tenant application using Spring and Hibernate with separate databases.
I would like my application to work even if one of my datasources is inaccessible (in case of problem), so that the other tenants can still access their data. That's why I don't want my application to check the datasources at deployment time. I tried to tell to not look up for datasources at start time :
applicationContext-datasources.xml :
<!-- data source 1 -->
<jee:jndi-lookup id="ds1" jndi-name="jdbc/ds1" resource-ref="true" lookup-on-startup="false" expected-type="javax.sql.DataSource" />
<!-- data source 2 -->
<jee:jndi-lookup id="ds2" jndi-name="jdbc/ds2" resource-ref="true" lookup-on-startup="false" expected-type="javax.sql.DataSource" />
But I get this exception stack :
11:24:10,192 INFO [STDOUT] 2014-11-28 11:24:10,189 - ERROR [main (ContextLoader.java:307) - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myDAO': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in file [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.jndi.JndiLookupFailureException: JndiObjectTargetSource failed to obtain new target object; nested exception is javax.naming.NameNotFoundException: jdbc not bound
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in file [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.jndi.JndiLookupFailureException: JndiObjectTargetSource failed to obtain new target object; nested exception is javax.naming.NameNotFoundException: jdbc not bound
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:342)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
...
Caused by: org.springframework.jndi.JndiLookupFailureException: JndiObjectTargetSource failed to obtain new target object; nested exception is javax.naming.NameNotFoundException: jdbc not bound
at org.springframework.jndi.JndiObjectTargetSource.getTarget(JndiObjectTargetSource.java:139)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:182)
at $Proxy54.getConnection(Unknown Source)
at com.example.MultiTenantConnectionProviderImpl.getConnection(MultiTenantConnectionProviderImpl.java:45)
at com.example.MultiTenantConnectionProviderImpl.getAnyConnection(MultiTenantConnectionProviderImpl.java:31)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl$MultiTenantConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcServicesImpl.java:302)
...
Caused by: javax.naming.NameNotFoundException: jdbc not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104)
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
at org.springframework.jndi.JndiObjectTargetSource.getTarget(JndiObjectTargetSource.java:132)
...
If I set lookup-on-startup with true in applicationContext-datasources.xml, then it works perfectly fine, but I know it won't work the day one of my datasources is inaccessible, even for the other tenant.
Thanks in advance for your help.
I found a way to achieve my goal, but the solution is not perfect.
When I declare my class MultiTenantConnectionProviderImpl, in the method getAnyConnection(), I give a connection from a default database, which is shared by all tenants :
public class MultiTenantConnectionProviderImpl implements MultiTenantConnectionProvider, Stoppable {
#Override
public Connection getAnyConnection() throws SQLException {
return defaultDataSource.getConnection();
}
...
}
And I let ths other methods determine the current tenant.
Then, in applicationContext-datasources.xml, I can declare all other datasources as I wished :
applicationContext-datasources.xml :
<!-- default data source -->
<jee:jndi-lookup id="defaultDatasource" jndi-name="jdbc/defaultDatasource" resource-ref="true" lookup-on-startup="true" expected-type="javax.sql.DataSource" />
<!-- data source 1 -->
<jee:jndi-lookup id="ds1" jndi-name="jdbc/ds1" resource-ref="true" lookup-on-startup="false" expected-type="javax.sql.DataSource" />
<!-- data source 2 -->
<jee:jndi-lookup id="ds2" jndi-name="jdbc/ds2" resource-ref="true" lookup-on-startup="false" expected-type="javax.sql.DataSource" />
That way it works, but it requires a shared database.

Java, Hibernate - Runtime exception occured when running an existing project

The following exception is coming when I am trying to run an existing project. Any pointer will be very helpful.
Exception in thread "Thread-5" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in ServletContext resource [/WEB-INF/app_config/applicationContext-dao.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.HibernateTransactionManager]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.j
ava:965)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactor
y.java:898)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java
:485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:4
56)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.transaction.interceptor.TransactionAspectSupport.determineTransactionManager(TransactionAspectSupport.java:24
8)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:100)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621)
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.Hibern
ateTransactionManager]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:74)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:958) 48535,34 97%
Caused by: java.lang.NullPointerException
at org.apache.commons.logging.LogFactory.getCachedFactory(LogFactory.java:979)
at org.apache.commons.logging.LogFactory.getFactory(LogFactory.java:435) 48536,34 97%
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685)
48573,27-34 97%
below is how the bean is defined
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
http://commons.apache.org/proper/commons-logging/apidocs/org/apache/commons/logging/LogFactory.html#getFactory()
See the link. It requires a commons-logging.properties do you have any file like that in classpath?
İt can't find bean class and return nullpointerexception .
Check all class and package names are true and check your app'sname.hbm.xml file is true named . You have to put class name which you run in app'sname area ..
And check you mapped your app'sname.hbm.xml file into hibernate.cfg.xml file

Categories

Resources