Hello,
I am trying to convert a portion of my configuration into Java configuration and the configuration class looks like this -
@Configuration
public class AppConfig {
@Bean
public org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean entityManagerFactory(){
org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean entityManagerFactory = new org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean();
entityManagerFactory.setDataSource(dataSource());
entityManagerFactory.setPersistenceUnitName("App1" );
entityManagerFactory.setJpaDialect(jpaDialect());
entityManagerFactory.setJpaVendorAdapter(jpaVendor Adapter());
entityManagerFactory.setPersistenceXmlLocation("/WEB-INF/persistence.xml");
return (LocalContainerEntityManagerFactoryBean) entityManagerFactory.getObject();
}
@Bean
public DataSource dataSource() {
org.springframework.jndi.JndiObjectFactoryBean dataSource = new org.springframework.jndi.JndiObjectFactoryBean();
dataSource.setJndiTemplate(jndiTemplate());
dataSource.setJndiName("java:comp/env/jdbc/app1_datasource");
return (DataSource) dataSource.getObject();
}
@Bean
public org.springframework.jndi.JndiTemplate jndiTemplate(){
org.springframework.jndi.JndiTemplate jndiTemplate = new org.springframework.jndi.JndiTemplate();
Properties environment = Environment.getProperties();
environment.setProperty("java.naming.factory.initi al", "weblogic.jndi.WLInitialContextFactory");
environment.setProperty("java.naming.provider.url" , "t3://localhost:7001");
jndiTemplate.setEnvironment(environment);
return jndiTemplate;
}
@Bean
public JpaDialect jpaDialect(){
org.springframework.orm.jpa.vendor.HibernateJpaDia lect jpaDialect = new org.springframework.orm.jpa.vendor.HibernateJpaDia lect();
return jpaDialect();
}
@Bean
public org.springframework.orm.jpa.vendor.HibernateJpaVen dorAdapter jpaVendorAdapter(){
org.springframework.orm.jpa.vendor.HibernateJpaVen dorAdapter vendorAdapter = new org.springframework.orm.jpa.vendor.HibernateJpaVen dorAdapter();
vendorAdapter.setDatabasePlatform("org.hibernate.d ialect.SQLServerDialect");
vendorAdapter.setGenerateDdl(true);
vendorAdapter.setShowSql(true);
return vendorAdapter;
}
@Bean
public org.springframework.flex.core.io.JpaHibernateConfi gProcessor jpaConfigProcessor(){
org.springframework.flex.core.io.JpaHibernateConfi gProcessor jpaConfigProcessor = new org.springframework.flex.core.io.JpaHibernateConfi gProcessor();
jpaConfigProcessor.setEntityManagerFactory(null);
return jpaConfigProcessor;
}
}
but when I try to use this configuration to startup my application -
I get this exception -
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'remoteService' defined in file [D:\STS26\workspace\app1\WebContent\WEB-INF\classes\com\appDAOclass]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.transaction.config.internalTr ansactionAdvisor': Cannot resolve reference to bean 'org.springframework.transaction.annotation.Annota tionTransactionAttributeSource#0' while setting bean property 'transactionAttributeSource'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.transaction.annotation.Annota tionTransactionAttributeSource#0': BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'auditAdvisor' defined in ServletContext resource [/WEB-INF/app-servlet.xml]: Cannot resolve reference to bean 'testAdvice' while setting bean property 'advice'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'testAdvice': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Could not autowire field: private com.dao.TestDAO com.aop.testAdvice.TestDAO; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/AppConfig.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionSt oreException: Factory method [public org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean com.AppConfig.entityManagerFactory()] threw exception; nested exception is java.lang.IllegalArgumentException: DataSource must not be null
Can someone let me know if something is missing?
Thanks & Regards
SK


Reply With Quote
...