fredycas83
Feb 1st, 2010, 02:45 PM
Hi guys, as i posted since few days, i still can not configure my application with jpa , jta and tomcat as a server.
I let you my configuration files just in case one of you knew how help me:
applicationContext.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:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd ">
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyP laceholderConfigurer">
<property name="location" value="WEB-INF/classes/database.properties" />
</bean>
<!-- Datasource -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerD ataSource"
p:driverClassName="${database.driverClassName}"
p:url="${database.url}"
p:username="${database.username}"
p:password="${database.password}">
</bean>
<!-- JPA EntityManagerFactory -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean"
p:dataSource-ref="dataSource">
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVen dorAdapter"
p:showSql="${jpa.showSql}"
p:database="${jpa.database}"
p:generateDdl="${jpa.generateDdl}">
</bean>
</property>
<property name="loadTimeWeaver">
<bean
class="org.springframework.instrument.classloading.Reflec tiveLoadTimeWeaver" />
</property>
</bean>
<!--
PostProcessors to perform exception translation on @Repository classes
(from native exceptions such as JPA PersistenceExceptions to Spring's
DataAccessException hierarchy).
-->
<bean
class="org.springframework.dao.annotation.PersistenceExce ptionTranslationPostProcessor" />
<bean
class="org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor" />
<!-- Transaction manager for JTA -->
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransaction Manager"/>
<!--
Instruct Spring to perform declarative transaction management
automatically on annotated classes.
-->
<tx:annotation-driven />
<!--
Activates various annotations to be detected in bean classes: Spring's
@Required and @Autowired, as well as JSR 250's @PostConstruct,
@PreDestroy and @Resource (if available) and JPA's @PersistenceContext
and @PersistenceUnit (if available).
-->
<context:component-scan base-package="com.services.impl" />
<context:component-scan base-package="com.persistence" />
<!--
Instruct Spring to retrieve and apply @AspectJ aspects which are
defined as beans in this context (such as the UsageLogAspect below).
-->
<aop:aspectj-autoproxy />
</beans>
persistence.xml
<persistence-unit name="Spring-2.5" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/SPRINGDS</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect" />
</properties>
</persistence-unit>
UserServiceImpl
@Repository("userService")
@Transactional
public class UserServiceImpl implements UserService {
@PersistenceContext(name="Spring-2.5")
private EntityManager entityManager;
public User saveUser(User user) {
try{
entityManager.persist(user);
} catch(Exception ex){
ex.printStackTrace();
}
return user;
}
}
and context.xml in Tomcat configuration
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Loader loaderClass="org.springframework.instrument.classloading.tomcat .TomcatInstrumentableClassLoader"
useSystemClassLoaderAsParent="false" />
<Resource name="SPRINGDS"
auth="Container"
type="javax.sql.DataSource"
maxActive="10"
maxIdle="5"
maxWait="15000"
removeAbandoned="true"
removeAbandonedTimeout="300"
logAbandoned="true"
initialSize="2"
minIdle="2"
username="spring"
password="spring"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521:XE"/>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
I let you my configuration files just in case one of you knew how help me:
applicationContext.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:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd ">
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyP laceholderConfigurer">
<property name="location" value="WEB-INF/classes/database.properties" />
</bean>
<!-- Datasource -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerD ataSource"
p:driverClassName="${database.driverClassName}"
p:url="${database.url}"
p:username="${database.username}"
p:password="${database.password}">
</bean>
<!-- JPA EntityManagerFactory -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean"
p:dataSource-ref="dataSource">
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVen dorAdapter"
p:showSql="${jpa.showSql}"
p:database="${jpa.database}"
p:generateDdl="${jpa.generateDdl}">
</bean>
</property>
<property name="loadTimeWeaver">
<bean
class="org.springframework.instrument.classloading.Reflec tiveLoadTimeWeaver" />
</property>
</bean>
<!--
PostProcessors to perform exception translation on @Repository classes
(from native exceptions such as JPA PersistenceExceptions to Spring's
DataAccessException hierarchy).
-->
<bean
class="org.springframework.dao.annotation.PersistenceExce ptionTranslationPostProcessor" />
<bean
class="org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor" />
<!-- Transaction manager for JTA -->
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransaction Manager"/>
<!--
Instruct Spring to perform declarative transaction management
automatically on annotated classes.
-->
<tx:annotation-driven />
<!--
Activates various annotations to be detected in bean classes: Spring's
@Required and @Autowired, as well as JSR 250's @PostConstruct,
@PreDestroy and @Resource (if available) and JPA's @PersistenceContext
and @PersistenceUnit (if available).
-->
<context:component-scan base-package="com.services.impl" />
<context:component-scan base-package="com.persistence" />
<!--
Instruct Spring to retrieve and apply @AspectJ aspects which are
defined as beans in this context (such as the UsageLogAspect below).
-->
<aop:aspectj-autoproxy />
</beans>
persistence.xml
<persistence-unit name="Spring-2.5" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/SPRINGDS</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect" />
</properties>
</persistence-unit>
UserServiceImpl
@Repository("userService")
@Transactional
public class UserServiceImpl implements UserService {
@PersistenceContext(name="Spring-2.5")
private EntityManager entityManager;
public User saveUser(User user) {
try{
entityManager.persist(user);
} catch(Exception ex){
ex.printStackTrace();
}
return user;
}
}
and context.xml in Tomcat configuration
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Loader loaderClass="org.springframework.instrument.classloading.tomcat .TomcatInstrumentableClassLoader"
useSystemClassLoaderAsParent="false" />
<Resource name="SPRINGDS"
auth="Container"
type="javax.sql.DataSource"
maxActive="10"
maxIdle="5"
maxWait="15000"
removeAbandoned="true"
removeAbandonedTimeout="300"
logAbandoned="true"
initialSize="2"
minIdle="2"
username="spring"
password="spring"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521:XE"/>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>