2

我在服务类中的 EntityManager 上遇到了 NullPointerException。从 JSBOSS 战争部署日志中可以看出,我的 spring 单例完全实例化,我的持久性单元也是如此。

这是我的代码:persistence.xml:

<persistence-unit name="sisweb-edi" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>java:/jdbc/sisweb-edi</jta-data-source>

    <class>com.sis.web.edi.domain.Codification</class>
    <class>com.sis.web.edi.domain.Dossier</class>
    <exclude-unlisted-classes/>

    <properties>
        <property name="hibernate.hbm2ddl.auto" value="validate"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
        <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
    </properties>
</persistence-unit>

JBOSS DS定义:

<datasource jta="true" jndi-name="java:/jdbc/sisweb-edi" pool-name="sisweb-edi" enabled="true" use-ccm="false">
  <connection-url>jdbc:oracle:thin:@xxx:1521:xxx</connection-url>
  <driver-class>oracle.jdbc.OracleDriver</driver-class>
  <driver>oracle.jdbc</driver>
  <security>
    <user-name>xxx</user-name>
    <password>xxx</password>
  </security>
  <validation>
    <validate-on-match>false</validate-on-match>
    <background-validation>false</background-validation>
  </validation>
  <statement>
   <share-prepared-statements>false</share-prepared-statements>
  </statement>
</datasource>

编码服务.java:

@Named
public class CodificationService {

/**
 * EntityManager
 */
@PersistenceContext(unitName = "sisweb-edi")
private EntityManager em;

/**
 * Get the Codification by the typeVoie
 * 
 * @param typeVoie String
 * @return Codification
 */
public Codification getCodificationByTypeVoie(String typeVoie) {
    Query query = em.createNamedQuery(Codification.Q_FIND_BY_TYPE_VOIE);
    query.setParameter(Codification.P_TYPE_VOIE, typeVoie);
    return (Codification) query.getSingleResult();
}
}

最后从服务器引导程序获取日志,直到出现 NullPointerException:

19:32:12,316 INFO  [org.jboss.modules] JBoss Modules version 1.1.1.GA
19:32:12,623 INFO  [org.jboss.msc] JBoss MSC version 1.0.2.GA
19:32:12,700 INFO  [org.jboss.as] JBAS015899: JBoss AS 7.1.1.Final "Brontes" starting
19:32:13,782 INFO  [org.xnio] XNIO Version 3.0.3.GA
19:32:13,783 INFO  [org.jboss.as.server] JBAS015888: Creating http management service     using socket-binding (management-http)
19:32:13,794 INFO  [org.xnio.nio] XNIO NIO Implementation Version 3.0.3.GA
19:32:13,802 INFO  [org.jboss.remoting] JBoss Remoting version 3.2.3.GA
19:32:13,827 INFO  [org.jboss.as.logging] JBAS011502: Removing bootstrap log handlers
19:32:13,835 INFO  [org.jboss.as.configadmin] (ServerService Thread Pool -- 26) JBAS016200: Activating ConfigAdmin Subsystem
19:32:13,848 INFO  [org.jboss.as.naming] (ServerService Thread Pool -- 38) JBAS011800: Activating Naming Subsystem
19:32:13,853 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 31) JBAS010280: Activating Infinispan subsystem.
19:32:13,855 INFO  [org.jboss.as.osgi] (ServerService Thread Pool -- 39) JBAS011940: Activating OSGi Subsystem
19:32:13,891 INFO  [org.jboss.as.webservices] (ServerService Thread Pool -- 48) JBAS015537: Activating WebServices Extension
19:32:13,900 INFO  [org.jboss.as.security] (ServerService Thread Pool -- 44) JBAS013101: Activating Security Subsystem
19:32:13,907 INFO  [org.jboss.as.security] (MSC service thread 1-5) JBAS013100: Current PicketBox version=4.0.7.Final
19:32:14,004 INFO  [org.jboss.as.connector] (MSC service thread 1-7) JBAS010408: Starting JCA Subsystem (JBoss IronJacamar 1.0.9.Final)
19:32:14,006 INFO  [org.jboss.as.naming] (MSC service thread 1-7) JBAS011802: Starting Naming Service
19:32:14,053 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-1) JBAS015400: Bound mail session [java:jboss/mail/Default]
19:32:14,160 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
19:32:14,182 INFO  [org.jboss.ws.common.management.AbstractServerConfig] (MSC service thread 1-8) JBoss Web Services - Stack CXF Server 4.0.2.GA
19:32:14,281 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010403: Deploying JDBC-compliant driver class oracle.jdbc.OracleDriver (version 11.2)
19:32:14,641 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015876: Starting deployment of "sisweb-edi.war"
19:32:14,647 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-5) JBAS015012: Started FileSystemDeploymentService for directory D:\tools\jboss-as-7.1.1.Final\standalone\deployments
19:32:14,936 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-7) JBAS010400: Bound data source [java:/jdbc/sisweb-edi]
19:32:14,936 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
19:32:16,795 INFO  [org.jboss.as.jpa] (MSC service thread 1-2) JBAS011401: Read persistence.xml for sisweb-edi
19:32:17,268 INFO  [org.jboss.as.jpa] (MSC service thread 1-6) JBAS011402: Starting Persistence Unit Service 'sisweb-edi.war#sisweb-edi'
19:32:17,479 INFO  [org.hibernate.annotations.common.Version] (MSC service thread 1-6) HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
19:32:17,487 INFO  [org.hibernate.Version] (MSC service thread 1-6) HHH000412: Hibernate Core {4.0.1.Final}
19:32:17,490 INFO  [org.hibernate.cfg.Environment] (MSC service thread 1-6) HHH000206: hibernate.properties not found
19:32:17,493 INFO  [org.hibernate.cfg.Environment] (MSC service thread 1-6) HHH000021: Bytecode provider name : javassist
19:32:17,521 INFO  [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-6) HHH000204: Processing PersistenceUnitInfo [name: sisweb-edi...]
19:32:17,846 WARN  [org.hibernate.mapping.RootClass] (MSC service thread 1-6) HHH000038: Composite-id class does not override equals(): com.sis.web.edi.domain.CodificationPK
19:32:17,847 WARN  [org.hibernate.mapping.RootClass] (MSC service thread 1-6) HHH000039: Composite-id class does not override hashCode(): com.sis.web.edi.domain.CodificationPK
19:32:17,852 INFO  [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] (MSC service thread 1-6) HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
19:32:18,172 INFO  [org.hibernate.dialect.Dialect] (MSC service thread 1-6) HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
19:32:18,191 INFO  [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (MSC service thread 1-6) HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory
19:32:18,195 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (MSC service thread 1-6) HHH000397: Using ASTQueryTranslatorFactory
19:32:18,241 INFO  [org.hibernate.validator.util.Version] (MSC service thread 1-6) Hibernate Validator 4.2.0.Final
19:32:18,656 INFO  [org.hibernate.tool.hbm2ddl.SchemaValidator] (MSC service thread 1-6) HHH000229: Running schema validator
19:32:18,657 INFO  [org.hibernate.tool.hbm2ddl.SchemaValidator] (MSC service thread 1-6) HHH000102: Fetching database metadata
19:32:18,777 INFO  [org.hibernate.tool.hbm2ddl.TableMetadata] (MSC service thread 1-6) HHH000261: Table found: SARAXO.CODIFICATION
19:32:18,778 INFO  [org.hibernate.tool.hbm2ddl.TableMetadata] (MSC service thread 1-6) HHH000037: Columns: [cod_valide, ns_class, cod_itineraire_type, cod_palette_ordre_aff, cod_temps_armement, cod_libelle_court, cod_moyen_type, cod_scenario, cod_facturation, cod_libelle, cod_icone_nom, cod_code_fiche, cod_profil, cod_dec_t_moy, cod_action, cod_type, cod_ordre_aff, cod_rayon_base, cod_exec_ok, cod_rayon_palier, cod_zoom_max, cod_code, cod_libelle_google, cod_ordre_sta, cod_code_famille]
19:32:18,862 INFO  [org.hibernate.tool.hbm2ddl.TableMetadata] (MSC service thread 1-6) HHH000261: Table found: SARAXO.DOSSIER
19:32:18,864 INFO  [org.hibernate.tool.hbm2ddl.TableMetadata] (MSC service thread 1-6) HHH000037: Columns: [dos_int_type_voie, dos_raison, dos_date_sys, dos_nb_victime, dos_provenance, dos_poste_tel, dos_dec_sid, dos_incarcere, dos_int_etg, dos_devenir, dos_raison_lib, dos_t2_service, doss_proprietaire, dos_ope2, dos_ope1, dos_t2, dos_circonstance, dos_int_nom_voie, dos_sismap_gps_x, dos_r_moy_pai, dos_sismap_gps_y, dos_repe_num, dos_app_num_voie, dos_profil, dos_int_pays, dos_int_itineraire, dos_app_code_postal, dos_voie_id, dos_date_maj, dos_int_compl_etare, dos_iter_num, dos_classe, dos_num, dos_r_corresd, dos_t2_fax, dos_int_compl_quartier, dos_date_creation, dos_num_distant, dos_com_ass, dos_r_correso, dos_app_prenom, dos_r_evs, dos_application_smur, dos_med_lib, dos_niveau_gravite, dos_circ_lib, dos_app_type_voie, dos_quartier_id, dos_google_precision, dos_sismap_precision, dos_int_part_voie, dos_action, dos_app_part_voie, dos_digicode, dos_cd_billet, dos_int_departement, dos_int_compl_voie, dos_app_telealarme, dos_victime_nom, dos_app_dem_lib, dos_app_quartier, dos_cd_certif, dos_int_com, dos_victime_prenom, dos_delest_dosnum, dos_app_nom_voie, dos_med_hos, dos_com_id, dos_etare_id, dos_app_demande, dos_observation, dos_t2_date, dos_gps_x, dos_gps_y, dos_app_com, dos_devenir_lib, dos_app_type_lib, dos_etat, dos_t2_nom_co, dos_app_type, dos_t2_poste, dos_int_code_postal, dos_dos_assist, dos_int_quartier, dos_app_nom, dos_bil_rqs, ns_class, dos_int_num_tel, dos_int_type_lieu, dos_val_ope, dos_provenance_lib, dos_r_servo, dos_t2_tel_co, dos_int_etare, dos_r_servd, dos_int_ty_l_lib, dos_app_num_tel, doss_couplage_type, dos_login_upd, dos_app_etare, dos_int_appart, dos_int_region, dos_cd_ass_prv, dos_adresse_google, dos_bt, dos_sid, dos_r_per_ass, dos_int_compl_commune, dos_int_adresse_libre, dos_val_date, dos_r_etabd, dos_delest_dept, dos_con, dos_int_num_voie, dos_delest_etat, dos_r_etabo]
19:32:19,048 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/sisweb-edi]] (MSC service thread 1-4) No Spring WebApplicationInitializer types detected on classpath
19:32:19,076 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/sisweb-edi]] (MSC service thread 1-4) Initializing Spring root WebApplicationContext
19:32:19,077 INFO  [org.springframework.web.context.ContextLoader] (MSC service thread 1-4) Root WebApplicationContext: initialization started
19:32:19,157 INFO  [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] (MSC service thread 1-4) Refreshing Root WebApplicationContext: startup date [Mon Nov 19 19:32:19 CET 2012]; root of context hierarchy
19:32:19,196 INFO  [org.springframework.context.annotation.ClassPathBeanDefinitionScanner] (MSC service thread 1-4) JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
19:32:19,199 INFO  [org.springframework.context.annotation.ClassPathBeanDefinitionScanner] (MSC service thread 1-4) JSR-330 'javax.inject.Named' annotation found and supported for component scanning
19:32:19,200 INFO  [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] (MSC service thread 1-4) Successfully resolved class for [com.sis.web.edi.config.ServiceEDIConfig]
 19:32:19,260 INFO [org.springframework.context.annotation.ClassPathBeanDefinitionScanner] (MSC service thread 1-4) JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
 19:32:19,260 INFO  [org.springframework.context.annotation.ClassPathBeanDefinitionScanner] (MSC service thread 1-4) JSR-330 'javax.inject.Named' annotation found and supported for component scanning
19:32:19,392 INFO  [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (MSC service thread 1-4) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
19:32:19,439 INFO  [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-4) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@42e28221: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,serviceEDIConfig,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0,dossierService,codificationService,org.springframework.aop.config.internalAutoProxyCreator,proxyTransactionManagementConfiguration,org.springframework.transaction.config.internalTransactionAdvisor,transactionAttributeSource,transactionInterceptor,sisweb-edi,jtaTransactionManager]; root of factory hierarchy
19:32:19,569 INFO  [org.springframework.transaction.jta.JtaTransactionManager] (MSC service thread 1-4) Using JTA UserTransaction: org.jboss.tm.usertx.client.ServerVMClientUserTransaction@7b884e45
19:32:19,570 INFO  [org.springframework.transaction.jta.JtaTransactionManager] (MSC service thread 1-4) Using JTA TransactionManager: com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate@4fdf5bae
19:32:19,574 INFO  [org.springframework.transaction.jta.JtaTransactionManager] (MSC service thread 1-4) Using JTA TransactionSynchronizationRegistry: com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple@5a005478
19:32:19,580 INFO  [org.springframework.web.context.ContextLoader] (MSC service thread 1-4) Root WebApplicationContext: initialization completed in 502 ms
19:32:19,656 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/sisweb-edi]] (MSC service thread 1-4) Initializing Spring FrameworkServlet 'webmvc'
19:32:19,656 INFO  [org.springframework.web.servlet.DispatcherServlet] (MSC service thread 1-4) FrameworkServlet 'webmvc': initialization started
19:32:19,661 INFO  [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] (MSC service thread 1-4) Refreshing WebApplicationContext for namespace 'webmvc-servlet': startup date [Mon Nov 19 19:32:19 CET 2012]; parent: Root WebApplicationContext
19:32:19,663 INFO  [org.springframework.context.annotation.ClassPathBeanDefinitionScanner] (MSC service thread 1-4) JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
19:32:19,664 INFO  [org.springframework.context.annotation.ClassPathBeanDefinitionScanner] (MSC service thread 1-4) JSR-330 'javax.inject.Named' annotation found and supported for component scanning
19:32:19,665 INFO  [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] (MSC service thread 1-4) Successfully resolved class for [com.sis.web.edi.config.WebEDIAppConfig]
19:32:19,676 INFO  [org.springframework.context.annotation.ClassPathBeanDefinitionScanner] (MSC service thread 1-4) JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
19:32:19,677 INFO  [org.springframework.context.annotation.ClassPathBeanDefinitionScanner] (MSC service thread 1-4) JSR-330 'javax.inject.Named' annotation found and supported for component scanning
19:32:19,743 INFO  [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (MSC service thread 1-4) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
19:32:19,770 INFO  [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-4) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@29d63b21: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,webEDIAppConfig,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0,dossierController,delegatingWebMvcConfiguration,requestMappingHandlerMapping,viewControllerHandlerMapping,beanNameHandlerMapping,resourceHandlerMapping,defaultServletHandlerMapping,requestMappingHandlerAdapter,mvcConversionService,mvcValidator,httpRequestHandlerAdapter,simpleControllerHandlerAdapter,handlerExceptionResolver,messageSource,propertySourcesPlaceholderConfigurer]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@42e28221
19:32:19,883 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-4) Mapped "{[/dossier/{id}/context],methods=[GET],params=[],headers=[],consumes=[],produces=[application/json],custom=[]}" onto public com.sis.web.edi.dto.DossierDTO com.sis.web.edi.web.DossierController.getDossier(java.lang.Integer)
19:32:20,304 INFO  [org.springframework.web.servlet.DispatcherServlet] (MSC service thread 1-4) FrameworkServlet 'webmvc': initialization completed in 647 ms
19:32:20,314 INFO  [org.jboss.web] (MSC service thread 1-4) JBAS018210: Registering web context: /sisweb-edi
19:32:20,328 INFO  [org.jboss.as.server] (Controller Boot Thread) JBAS018559: Deployed "sisweb-edi.war"
19:32:20,522 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss AS 7.1.1.Final "Brontes" started in 8582ms - Started 234 of 312 services (76 services are passive or on-demand)
19:32:32,385 ERROR [com.sis.web.edi.web.DossierController] HTTP 500: java.lang.NullPointerException
at com.sis.web.edi.service.DossierService.getDossier(DossierService.java:33) [edi-service-0.1-SNAPSHOT.jar:]
at com.sis.web.edi.web.DossierController.getDossier(DossierController.java:61) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_07]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_07]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_07]
at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_07]
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213) [spring-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126) [spring-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96) [spring-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617) [spring-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578) [spring-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) [spring-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923) [spring-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) [spring-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) [spring-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) [spring-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_07]

有什么可能出错的提示吗?

编辑:如果我查找 EntityManagerFactory 并从中创建一个 EntityManager,则 EntityManager 是正确的 EntityManagerFactory emf = new JndiTemplate().lookup("java:comp/env/persistence/sisweb- edi", EntityManagerFactory.class); em = emf.createEntityManager();

4

1 回答 1

1

我只是缺少一个从 web 容器 EntityManagerFactory 实现中注入 EntityManager 的 spring 依赖项。

我添加了

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-orm</artifactId>
  <version>${spring.version}</version>
  <scope>runtime</scope>
</dependency>

现在它正在工作(我发现在实施我的单元测试时:单元测试再次证明了它的效率!)

于 2012-11-21T13:10:30.650 回答