yfm10 / ssh / JBoss5.0下启动Struts2+spring+hibernate...

分享

   

JBoss5.0下启动Struts2+spring+hibernate项目

2010-03-29  yfm10

Jboss5.0.0下,项目使用Struts2.1.6+Spring2.5.5+Hibernate3(使用JPA的Hibernate实现)框架,但是在Jboss下启动时总是抛出“java.lang.RuntimeException: Specification violation [EJB3 JPA 6.2.1.2] - You have not defined a non-jta-data-source for a RESOURCE_LOCAL enabled persistence context named: esys”的错误,错误信息如下:
15:38:56,359 INFO  [PersistenceUnitDeployment] Starting persistence unit persistence.unit:unitName=#esys
15:38:56,375 ERROR [AbstractKernelController] Error installing to Start: name=persistence.unit:unitName=#esys state=Create
java.lang.RuntimeException: Specification violation [EJB3 JPA 6.2.1.2] - You have not defined a non-jta-data-source for a RESOURCE_LOCAL enabled persistence context named: esys
at org.jboss.jpa.deployment.PersistenceUnitInfoImpl.<init>(PersistenceUnitInfoImpl.java:124)
at org.jboss.jpa.deployment.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:285)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:59)
at org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl.invoke(ReflectMethodInfoImpl.java:150)
at org.jboss.joinpoint.plugins.BasicMethodJoinPoint.dispatch(BasicMethodJoinPoint.java:66)
at org.jboss.kernel.plugins.dependency.KernelControllerContextAction$JoinpointDispatchWrapper.execute(KernelControllerContextAction.java:241)
at org.jboss.kernel.plugins.dependency.ExecutionWrapper.execute(ExecutionWrapper.java:47)
at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchExecutionWrapper(KernelControllerContextAction.java:109)
at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchJoinPoint(KernelControllerContextAction.java:70)
at org.jboss.kernel.plugins.dependency.LifecycleAction.installActionInternal(LifecycleAction.java:221)
at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:54)
at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:42)
at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1598)
at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1062)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:774)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:540)
at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.deploy(BeanMetaDataDeployer.java:121)
at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.deploy(BeanMetaDataDeployer.java:51)
at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)
at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439)
at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157)
at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1178)
at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098)
at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1598)
at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1062)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781)
at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:545)
at org.jboss.system.server.profileservice.ProfileServiceBootstrap.loadProfile(ProfileServiceBootstrap.java:304)
at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:205)
at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:405)
at org.jboss.Main.boot(Main.java:209)
at org.jboss.Main$1.run(Main.java:547)
at java.lang.Thread.run(Thread.java:619)
15:38:57,843 INFO  [TomcatDeployment] deploy, ctxPath=/eSys, vfsUrl=eSys.war
反编译了jboss安装目录下common\lib中的“jboss-jpa-deployers.jar”文件,发现此文件中抛出异常的“PersistenceUnitInfoImpl”类,有这么几句代码:
if (metaData.getProvider() != null) { setPersistenceProviderClassName(metaData.getProvider());
    }

    if (metaData.getJtaDataSource() != null)
    {
      setJtaDataSource((DataSource)ctx.lookup(metaData.getJtaDataSource()));
    }
    else if (transactionType == PersistenceUnitTransactionType.JTA)
    {
      throw new RuntimeException("Specification violation [EJB3 JPA 6.2.1.2] - You have not defined a jta-data-source for a JTA enabled persistence context named: " + metaData.getName());
    }

    if (metaData.getNonJtaDataSource() != null)
    {
      setNonJtaDataSource((DataSource)ctx.lookup(metaData.getNonJtaDataSource()));
    }
    else if (transactionType == PersistenceUnitTransactionType.RESOURCE_LOCAL)
    {
      throw new RuntimeException("Specification violation [EJB3 JPA 6.2.1.2] - You have not defined a non-jta-data-source for a RESOURCE_LOCAL enabled persistence context named: " + metaData.getName());
    }
按照这个意思就是persistence.xml中必须至少配置一个JNDI数据源,但是我使用的是spring管理的数据源,这个地方怎么会出现这种问题呢?

把配置文件贴出来

applicationContext_hibernate.xml

Xml代码 复制代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"  
  4.     xmlns:tx="http://www.springframework.org/schema/tx"  
  5.     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd   
  6.             http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd   
  7.             http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">  
  8.     <!--加载properties文件,供其他bean使用,用${...}来调用 -->  
  9.     <bean id="propertyConfigure"  
  10.         class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
  11.         <property name="locations">  
  12.             <list>  
  13.                 <value>/WEB-INF/springConfig/esys.properties</value>  
  14.             </list>  
  15.         </property>  
  16.     </bean>  
  17.   
  18.     <!--定义数据源-->  
  19.     <bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">  
  20.         <property name="driver">  
  21.             <value>${jdbc.driverClassName}</value>  
  22.         </property>  
  23.         <property name="driverUrl">  
  24.             <value>${jdbc.url}&amp;user=${jdbc.username}&amp;password=${jdbc.password}</value>  
  25.         </property>  
  26.         <property name="user"> <!-- 必须在这里也设置,但是 proxool却不使用它,或许是个bug-->  
  27.             <value>${jdbc.username}</value>  
  28.         </property>  
  29.         <property name="password"> <!-- 必须在这里也设置,但是 proxool却不使用它,或许是个bug-->  
  30.             <value>${jdbc.password}</value>  
  31.         </property>  
  32.         <property name="alias">  
  33.             <value>datapool</value>  
  34.         </property>  
  35.         <property name="houseKeepingSleepTime">  
  36.             <value>7200000</value>  
  37.         </property>  
  38.         <property name="prototypeCount">  
  39.             <value>5</value>  
  40.         </property>  
  41.         <property name="maximumConnectionCount">  
  42.             <value>100</value>  
  43.         </property>  
  44.         <property name="minimumConnectionCount">  
  45.             <value>10</value>  
  46.         </property>  
  47.         <property name="trace">  
  48.             <value>true</value>  
  49.         </property>  
  50.         <property name="verbose">  
  51.             <value>true</value>  
  52.         </property>  
  53.     </bean>  
  54.        
  55.     <!-- 实体管理工厂 -->  
  56.     <bean id="entityManagerFactory"  
  57.         class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"  
  58.         scope="singleton">  
  59.         <property name="persistenceUnitName" value="esys"/>  
  60.         <property name="dataSource">  
  61.             <ref bean="dataSource" />  
  62.         </property>  
  63.         <property name="jpaVendorAdapter">  
  64.             <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">  
  65.                 <property name="database">  
  66.                     <value>${hibernate.database}</value>  
  67.                 </property>  
  68.                 <property name="showSql"><!-- 是否显示SQL -->  
  69.                     <value>${hibernate.show_sql}</value>  
  70.                 </property>  
  71.                 <property name="generateDdl"><!--是否自动生成DDL-->  
  72.                     <value>${hibernate.generateDdl}</value>  
  73.                 </property>  
  74.             </bean>  
  75.         </property>  
  76.     </bean>  
  77.   
  78.     <!-- 事务管理 -->  
  79.     <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">  
  80.         <property name="entityManagerFactory" ref="entityManagerFactory" />  
  81.     </bean>  
  82.     <tx:annotation-driven transaction-manager="transactionManager" /><!-- 允许代码中通过标记控制事务 -->  
  83.        
  84.     <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /><!--  -->  
  85.        
  86.     <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />  
  87.        
  88.     <bean id="baseTxProxy" lazy-init="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" scope="singleton">  
  89.         <property name="transactionManager">  
  90.             <ref local="transactionManager" />  
  91.         </property>  
  92.         <property name="transactionAttributes">  
  93.             <props>  
  94.                 <prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>  
  95.                 <prop key="exe*">PROPAGATION_REQUIRED,-Exception</prop>  
  96.                 <prop key="add*">PROPAGATION_REQUIRED,-Exception</prop>  
  97.                 <prop key="persist*">PROPAGATION_REQUIRED,-Exception</prop>  
  98.                 <prop key="remove*">PROPAGATION_REQUIRED,-Exception</prop>  
  99.                 <prop key="del*">PROPAGATION_REQUIRED,-Exception</prop>  
  100.                 <prop key="gen*">PROPAGATION_REQUIRED,-Exception</prop>  
  101.                 <prop key="finish*">PROPAGATION_REQUIRED,-Exception</prop>  
  102.                 <prop key="create*">PROPAGATION_REQUIRED,-Exception</prop>  
  103.                 <prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>  
  104.                 <prop key="merge*">PROPAGATION_REQUIRED,-Exception</prop>  
  105.             </props>  
  106.         </property>  
  107.     </bean>  
  108.        
  109.   
  110. </beans>  

 persistence.xml

Xml代码 复制代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <persistence xmlns="http://java.sun.com/xml/ns/persistence"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xsi:schemaLocation="http://java.sun.com/xml/ns/persistence   
  5.     http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"   
  6.     version="1.0">  
  7.   
  8.     <persistence-unit name="esys" transaction-type="RESOURCE_LOCAL">  
  9.         <provider>org.hibernate.ejb.HibernatePersistence</provider>  
  10.         <properties>  
  11.             <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />  
  12.             <!-- <property name="hibernate.hbm2ddl.auto" value="create-drop" /> -->  
  13.             <property name="hibernate.show_sql" value="true" />  
  14.             <property name="hibernate.format_sql" value="true" />  
  15.         </properties>  
  16.     </persistence-unit>  
  17. </persistence>  
 

web.xml

 

 

 


问题补充:
persistence.xml中“persistence-unit”是必须的,而且必须与applicationContext中指定的“persistenceUnitName”同名,再加上系统不使用JTA事物,transaction-type="RESOURCE_LOCAL"好像也是必须。其他的配置信息曾经去掉过,可是不起作用。倒是在persistence.xml中加上一个空的
<non-jta-data-source></non-jta-data-source>
启动的时候不再抛异常了。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。

    来自: yfm10 > 《ssh》

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多
    喜欢该文的人也喜欢 更多

    ×
    ×

    ¥.00

    微信或支付宝扫码支付:

    开通即同意《个图VIP服务协议》

    全部>>