Spring+JPA部署到Jboss遇到的问题
1.删除跟servlet相关的包
2.删除xerces*.jar,xml-apis*.jar
3.删除jboss-common-core包,因为JBoss下已经存在该包
4 发现数据库连接使用localhost不行,竟然用127.0.0.1就可以。
<?xml version="1.0" encoding="UTF-8"?> <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_1_0.xsd" version="1.0"> <persistence-unit name="AppPU" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <non-jta-data-source> </non-jta-data-source> <properties> <!-- show sql --> <property name="hibernate.show_sql" value="true" /> <!-- dialect --> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> </properties> </persistence-unit> </persistence>
<beansxmlns="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"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-2.5.xsdhttp://www.springframework.org/schema/jeehttp://www.springframework.org/schema/jee/spring-jee-2.5.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-2.5.xsd"
default-lazy-init="true">
<description>Spring</description>
<beanid="jdbcConfigurer"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<propertyname="location"value="classpath:jdbc.properties"/>
</bean>
<beanid="dataSource"class="org.apache.commons.dbcp.BasicDataSource"destroy-method="close">
<propertyname="driverClassName"><value>${jdbc.driverClassName}</value></property>
<propertyname="url"><value>${jdbc.url}</value></property>
<propertyname="username"><value>${jdbc.username}</value></property>
<propertyname="password"><value>${jdbc.password}</value></property>
<propertyname="maxActive"><value>300</value></property>
<propertyname="maxIdle"><value>100</value></property>
<propertyname="maxWait"><value>10000</value></property>
<propertyname="removeAbandoned"><value>true</value></property>
<propertyname="removeAbandonedTimeout"><value>100</value></property>
<propertyname="logAbandoned"><value>true</value></property>
</bean>
<!--JPA配置,读取persistence.xml中的PU-->
<beanid="entityManagerFactory"class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<propertyname="persistenceUnitName"value="AppPU"/>
<propertyname="dataSource"ref="dataSource"/>
<propertyname="persistenceXmlLocation"value="classpath:META-INF/persistence.xml"/>
<propertyname="loadTimeWeaver">
<beanclass="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>
</bean>
<!--事务配置-->
<beanid="transactionManager"class="org.springframework.orm.jpa.JpaTransactionManager">
<propertyname="entityManagerFactory"ref="entityManagerFactory"/>
</bean>
<!--使用annotation定义事务-->
<tx:annotation-driventransaction-manager="transactionManager"/>
<!--保证POJO中标注@Required的属性被注入-->
<beanclass="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/>
<!--导出用annotation注释的JMXPOJO-->
<context:mbean-export/>
</beans>之前在web.xml中加上了如下代码:
<param-name>contextClass</param-name>
<param-value>
org.jboss.spring.vfs.context.VFSXmlWebApplicationContext
</param-value>
</context-param>还有引入了三个包, snowdrop-weaving-1.0.1.GA.jar
snowdrop-vfs-1.0.1.GA.jar
snowdrop-deployers-1.0.1.GA.jar
目前还不是很肯定这些包的作用