How do I make this spring class not found error go away? - eclipse

Will someone please explain why I'm getting this build error, when the class is obviously there. Here's the error -
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/spring-servlet.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/aop/scope/ScopedProxyUtils
and here's my spring-servlet.xml file -
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:annotation-config />
<context:component-scan
base-package="com.website" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<value>/WEB-INF/messages/messages</value>
</property>
<property name="cacheSeconds" value="60" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
</beans>
I also have the aop jar on my classpath-
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/org.springframework.aop-sources-3.0.5.RELEASE.jar"/>

That is the sources jar...
path="WebContent/WEB-INF/lib/org.springframework.aop-sources-3.0.5.RELEASE.jar"
Get the binary release version.

Related

Spring batch meta data mannuvally creation in Job Respository

In mysql meta data manually creation time am getting this exception.
please suggest me any one.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.jdbc.datasource.init.DataSourceInitializer#0': Invocation of init method failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: Failed to execute database script; nested exception is org.springframework.jdbc.datasource.init.CannotReadScriptException: Cannot read SQL script from class path resource [org/springframework/batch/core/schema-drop-mysql.sql]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1548)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:660)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
at john.deere.com.MetaApp.main(MetaApp.java:13)
Caused by: org.springframework.dao.DataAccessResourceFailureException: Failed to execute database script; nested exception is org.springframework.jdbc.datasource.init.CannotReadScriptException: Cannot read SQL script from class path resource [org/springframework/batch/core/schema-drop-mysql.sql]
at org.springframework.jdbc.datasource.init.DatabasePopulatorUtils.execute(DatabasePopulatorUtils.java:56)
at org.springframework.jdbc.datasource.init.DataSourceInitializer.afterPropertiesSet(DataSourceInitializer.java:84)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1607)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1544)
... 12 more
Caused by: org.springframework.jdbc.datasource.init.CannotReadScriptException: Cannot read SQL script from class path resource [org/springframework/batch/core/schema-drop-mysql.sql]
at org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.executeSqlScript(ResourceDatabasePopulator.java:171)
at org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.populate(ResourceDatabasePopulator.java:135)
at org.springframework.jdbc.datasource.init.CompositeDatabasePopulator.populate(CompositeDatabasePopulator.java:56)
at org.springframework.jdbc.datasource.init.DatabasePopulatorUtils.execute(DatabasePopulatorUtils.java:47)
... 15 more
Caused by: java.io.FileNotFoundException: class path resource [org/springframework/batch/core/schema-drop-mysql.sql] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158)
at org.springframework.core.io.support.EncodedResource.getReader(EncodedResource.java:132)
at org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.readScript(ResourceDatabasePopulator.java:228)
at org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.executeSqlScript(ResourceDatabasePopulator.java:168)
... 18 more
am traying to execute this..
In my applicationDb.xml is
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<!-- connect to database -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/MANU" />
<property name="username" value="root" />
<property name="password" value="****" />
</bean>
<bean id="transactionManager"
class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="org/springframework/batch/core/schema-drop-mysql.sql"/>
<jdbc:script location="org/springframework/batch/core/schema-mysql.sql" />
</jdbc:initialize-database>
</beans>
AND MY APPLICATION.XML IS
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="transactionManager" />
<property name="databaseType" value="mysql" />
</bean>
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository"/>
</bean>
<bean id="simpleJob" class="org.springframework.batch.core.job.SimpleJob" abstract="true">
<property name="jobRepository" ref="jobRepository" />
</bean>
</beans>

Redirect after logout to the wrong language

I am using spring security and i18n.
My application has 2 languages: Fr and En, Fr being the default one. However, when I logged in using the English languages and then log out, I will be redirected to the french homepage. I tried changing the logout url, including the language part, like this:
"/login/login.mvc?logout=True?language=i18n_get_lang()"
, but no success. Any idea how to solve this would be more than welcome.
PS, the login redirection works correctly.
Below is my springSecurity.xml
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
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/security
http://www.springframework.org/schema/security/spring-security-4.0.xsd">
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/login/login.mvc" access="isAnonymous()" />
<!-- <intercept-url pattern="/admin**" access="ROLE_USER" /> -->
<form-login
login-processing-url="/login/login.mvc"
login-page="/login/login.mvc"
default-target-url="/login/accueil.mvc"
authentication-failure-url="/login/login.mvc?Error=True"
username-parameter="j_username"
password-parameter="j_password" />
<logout logout-success-url="/login/login.mvc?logout=True?language=localeChangeInterceptor"
logout-url="/login/j_spring_security_logout"/>
<!-- unable csrf protection -->
<csrf disabled="true"/>
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="user" password="1234" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
My MVC-servlet.xml
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".jsp" />
</bean>
<mvc:resources mapping="/css/**" location="/css/" />
<mvc:resources mapping="/images/**" location="/images/" />
<mvc:resources mapping="/js/**" location="/js/" />
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:i18n/Message"/>
<property name="defaultEncoding" value="UTF-8"/>
</bean>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="defaultLocale" value="fr" />
</bean>
<bean id="localeChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="language" />
</bean>
<mvc:interceptors>
<!-- Changes the locale when a 'lang' request parameter is sent; e.g. /?lang=de -->
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="language"/>
</bean>
</mvc:interceptors>
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" >
<property name="interceptors">
<list>
<ref bean="localeChangeInterceptor" />
</list>
</property>
</bean>
</beans>
I found a solution: change SessionLocaleResolver to CookieLocaleResolver in MVC-servlet.xml.

xml schema for Springbatch3.0.1?

i am trying to accomplish spring batch in spring 3.0.1 and sufficient jars have been included in the class path.when i am trying to run the project with command line job runner i am getting a error that shows because of miss match xml schema for spring3.0.1. i have 3 differnt xml files as below
ApplicationContext.xml
<?xml version="1.0" encoding="UTF-8"?><?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans"
xsi:schemalocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<import resource="JobRepository.xml" />
</beans>
jobConfiguration.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
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/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<import resource="ApplicationContext.xml" />
<bean abstract="true"
class="org.springframework.batch.core.step.tasklet.TaskletStep" id="taskletStep">
<property name="jobRepository" ref="jobRepository" />
<property name="transactionManager" ref="transactionManager" />
</bean>
<bean class="com.mypackage.HelloWorldTasklet" id="helloTasklet">
<property name="message" value="Hello World!" />
</bean>
<bean class="com.mypackage.HelloWorldTasklet" id="createdByTasklet">
<property name="message" value="Created By Harish On Java" />
</bean>
<bean class="org.springframework.batch.core.job.SimpleJob" id="mySimpleJob">
<property name="name" value="mySimpleJob" />
<property name="steps">
<list>
<bean parent="taskletStep">
<property name="tasklet" ref="helloTasklet" />
</bean>
<bean parent="taskletStep">
<property name="tasklet" ref="createdByTasklet" />
</bean>
</list>
</property>
<property name="jobRepository" ref="jobRepository" />
</bean>
</beans>
JobRepository.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans"
xsi:schemalocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<bean
class="org.springframework.batch.core.repository.support.SimpleJobRepository"
id="jobRepository">
<constructor-arg>
<bean
class="org.springframework.batch.core.repository.dao.MapJobInstanceDao" />
</constructor-arg>
<constructor-arg>
<bean
class="org.springframework.batch.core.repository.dao.MapJobExecutionDao" />
</constructor-arg>
<constructor-arg>
<bean
class="org.springframework.batch.core.repository.dao.MapStepExecutionDao" />
</constructor-arg>
<constructor-arg>
<bean
class="org.springframework.batch.core.repository.dao.MapExecutionContextDao" />
</constructor-arg>
</bean>
<bean id="transactionManager"
class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
<bean class="org.springframework.batch.core.launch.support.SimpleJobLauncher"
id="jobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
</beans>
Java Code:
public class HelloWorldTasklet implements Tasklet {
private String message;
public void setMessage(String message) {
this.message = message;
}
#Override
public RepeatStatus execute(StepContribution contribution,
ChunkContext context) throws Exception {
// TODO Auto-generated method stub
System.out.println(message);
return RepeatStatus.FINISHED;
}
}
my lib contained following jars
com.springsource.org.aopalliance-1.0.0.jar
com.springsource.org.apache.commons.lang-sources-2.1.0.jar
com.springsource.org.apache.commons.logging-1.1.1.jar
com.springsource.org.apache.log4j-1.2.15.jar
commons-beanutils-1.8.3.jar
commons-codec-1.3.jar
commons-collections-3.2.jar
commons-digester-1.8.jar
commons-lang3-3.1.jar
commons-logging-1.1.1.jar
org.springframework.aop-3.0.1.RELEASE-A.jar
org.springframework.asm-3.0.1.RELEASE-A.jar
org.springframework.aspects-3.0.1.RELEASE-A.jar
org.springframework.beans-3.0.1.RELEASE-A.jar
org.springframework.context-3.0.1.RELEASE-A.jar
org.springframework.context.support-3.0.1.RELEASE-A.jar
org.springframework.core-3.0.1.RELEASE-A.jar
org.springframework.expression-3.0.1.RELEASE-A.jar
org.springframework.web-3.0.1.RELEASE-A.jar
org.springframework.web.servlet-3.0.1.RELEASE-A.jar
spring-batch-core-2.2.0.RELEASE.jar
spring-batch-infrastructure-2.2.0.RELEASE.jar
any response is appreciated greatly in advance.
You have the Spring Batch 2.2.0.RELEASE jars on your classpath, yet you aren't specifying that version in your schemas. Update to use the versions and you'll be fine.
As a side note, is there a reason you are not using the schemas in your configuration? While you're configuring batch components, you're doing it the hard way by not using the namespace or factory beans. For example, instead of:
<bean
class="org.springframework.batch.core.repository.support.SimpleJobRepository"
id="jobRepository">
<constructor-arg>
<bean
class="org.springframework.batch.core.repository.dao.MapJobInstanceDao" />
</constructor-arg>
<constructor-arg>
<bean
class="org.springframework.batch.core.repository.dao.MapJobExecutionDao" />
</constructor-arg>
<constructor-arg>
<bean
class="org.springframework.batch.core.repository.dao.MapStepExecutionDao" />
</constructor-arg>
<constructor-arg>
<bean
class="org.springframework.batch.core.repository.dao.MapExecutionContextDao" />
</constructor-arg>
</bean>
you can do this:
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="transactionManager" ref="transactionManager"/>
</bean>
We also have namespace support for the job configuration. Instead of:
<bean class="org.springframework.batch.core.job.SimpleJob" id="mySimpleJob">
<property name="name" value="mySimpleJob" />
<property name="steps">
<list>
<bean parent="taskletStep">
<property name="tasklet" ref="helloTasklet" />
</bean>
<bean parent="taskletStep">
<property name="tasklet" ref="createdByTasklet" />
</bean>
</list>
</property>
<property name="jobRepository" ref="jobRepository" />
</bean>
you should try this:
<batch:job id="mySimpleJob">
<batch:step id="step1" next="step2">
<batch:tasklet ref="helloTasklet"/>
</batch:step>
<batch:step id="step2">
<batch:tasklet ref="createdByTasklet"/>
</batch:step>
</batch:job>
The namespaces handle some niceties like auto wiring the job repositories and transaction managers, etc. I'd recommend you take a look at the Spring Batch documentation here: http://docs.spring.io/spring-batch/2.2.x/reference/html/index.html

How to create a bean which extends JpaRepository

I want to write a unit test for a DAO. But in our project, we have more than 200 DAO and 200 model classes. And we use jpaRepository to write DAO. But I have a problem when I run my unit test. I take a lot of time to create application context. I have an idea. I only create a bean DAO which I want to test instead of creating all DAO. But DAO of jpa:repository is interface, so I can not create a bean with class is interface. If creating a bean which extend jpa:reponsitories is imposible, can you suggest me other ways to run unit faster.
my unit test:
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations = {"classpath:META-INF/spring/testContext.xml"})
#TransactionConfiguration(defaultRollback = true)
// Importance, as the transaction will be rollback for each test
// give us a clean state.
#Transactional
public class CommunicationDetailDAOTest
{
#Autowired
CommunicationDetailDAO communicationDetailDAO;
#Test
public void testSomeThing()
{
System.out.println("helloworld");
}
}
file testContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
<bean id="placeholderConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:META-INF/spring/properties/prism_local_persistence_test.properties"/>
</bean>
<bean id="entityManager" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="persistenceXmlLocation" value="/META-INF/persistence.xml"/>
<property name="persistenceUnitName" value="mobilePersistenceUnit"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"></bean>
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${db.driver}"/>
<!--using postgres driver-->
<property name="url" value="${db.url}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="dataSource" ref="dataSource"></property>
<property name="entityManagerFactory" ref="entityManager"/>
</bean>
<!-- Spring Data Jpa setup -->
<jpa:repositories
base-package="com.discorp.model.dao"
entity-manager-factory-ref="entityManager"
transaction-manager-ref="transactionManager"></jpa:repositories>
<tx:annotation-driven transaction-manager="transactionManager"/>
<!--<context:component-scan base-package="com.qsoft"/>-->
</beans>
and file persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="mobilePersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.discorp.model.common.Address</class>
<class>com.discorp.model.common.Application</class>
.... more than 200 model classes
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.show_sql" value="false"/>
<!--<property name="hibernate." value="false"/> -->
</properties>
</persistence-unit>
</persistence>
Make different config files for different tests an include only the dao(s) needed by the test:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:repository="http://www.springframework.org/schema/data/repository"
...
xsi:schemaLocation="http://www.springframework.org/schema/beans
...
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/data/repository
http://www.springframework.org/schema/data/repository/spring-repository.xsd
...">
...
<jpa:repositories base-package="path.to.your" >
<repository:include-filter type="assignable" expression="path.to.your.Repository"/>
</jpa:repositories>

Conflicting persistence unit definitions

Spring 3.1.1
Maven 3.0.4
JPA
Eclipse wtp indigo
Hello,
I am getting the following exception on server startup. I have just one persistence.xml in my project. Any ideas? Thanks Eric
Caused by: java.lang.IllegalStateException: Conflicting persistence unit definitions for name 'cassandra_pu': file:/C:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/cassandra/WEB-INF/classes/, file:/C:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/cassandra/WEB-INF/classes/
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.preparePersistenceUnitInfos(DefaultPersistenceUnitManager.java:362)
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.afterPropertiesSet(DefaultPersistenceUnitManager.java:326)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:235)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 62 more
My context file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
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/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:component-scan base-package="hamacher.cassandra.controller" />
<context:component-scan base-package="hamacher.cassandra.dao" />
<context:component-scan base-package="hamacher.cassandra.service" />
<context:annotation-config />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="packagesToScan" value="hamacher.cassandra.entity"/>
<property name="persistenceUnitName" value="cassandra_pu"/>
</bean>
<tx:annotation-driven />
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
</beans>
My persistence.xml file is in META-INF where it should be:
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="cassandra_pu">
<provider>com.impetus.kundera.KunderaPersistence</provider>
<properties>
<property name="kundera.nodes" value="localhost"/>
<property name="kundera.port" value="9160"/>
<property name="kundera.keyspace" value="KunderaExamples"/>
<property name="kundera.dialect" value="cassandra"/>
<property name="kundera.client.lookup.class" value="com.impetus.client.cassandra.pelops.PelopsClientFactory" />
<property name="kundera.cache.provider.class" value="com.impetus.kundera.cache.ehcache.EhCacheProvider"/>
<property name="kundera.cache.config.resource" value="/ehcache-test.xml"/>
</properties>
</persistence-unit>
</persistence>
Try adding,
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="emf-p"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<!-- <property name="persistenceXmlLocation" value="/WEB-INF/classes/META-INF/persistence.xml" /> -->
<property name="persistenceUnitManager" ref="pum"/>
<property name="persistenceUnitName" value="personnel_cass_pu" />
<property name="loadTimeWeaver">
<bean
class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</property>
</bean>
To define your persistence.xml location with Spring bean.
You can also refer:
https://github.com/xamry/twitample/blob/master/src/main/resources/appContext.xml
for persistence.xml specific configuration.