Spring部署到JBOSS 7中没有加载hibernate实体

时间:2013-02-08 23:02:22

标签: spring hibernate jpa jboss7.x entitymanager

我有一个Spring MVC应用程序是使用使用hibernate配置了jpa的roo创建的。它创建了数据库并且可以很好地部署到STS提供的tomcat服务器中。但是当部署到JBOSS 7.1.1 AS时,它似乎找不到实体。我试过跟JBoss Spring Migration Guide。我想允许spring成为实体管理器,同时仍然部署到JBOSS,只需对默认的spring tomcat配置进行最少的配置更改。当我允许JBOSS成为实体管理器但我希望做的配置更改少于此方法所需的时候,我已经能够使用了。代码和日志是我从各个网站上找到的,描述了他们如何克服这个问题,但它似乎不适用于我的部署。

META-INF /弹簧/的applicationContext-jpa.xml

<bean id="dataSource" class="com.lmco.lmis.setup.EncryptedBasicDataSource"
    destroy-method="close">
    <!-- <bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" 
        id="dataSource"> -->
    <property name="driverClassName" value="${database.driverClassName}" />
    <property name="url" value="${database.url}" />
    <property name="username" value="${database.username}" />
    <property name="password" value="${database.password}" />
    <property name="testOnBorrow" value="true" />
    <property name="testOnReturn" value="true" />
    <property name="testWhileIdle" value="true" />
    <property name="timeBetweenEvictionRunsMillis" value="1800000" />
    <property name="numTestsPerEvictionRun" value="3" />
    <property name="minEvictableIdleTimeMillis" value="1800000" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
    </property>
    <property name="dataSource" ref="dataSource" />
    <property name="persistenceXmlLocation" value="classpath:META-INF/jpa-persistence.xml" />
</bean>

META-INF / JPA-persistence.xml中

<persistence-unit name="jpaHibernatePersistenceUnit"
    transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>
        <property name="jboss.as.jpa.managed" value="false" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />
        <!-- value="create" to build a new database on each run; value="update" 
            to modify an existing database; value="create-drop" means the same as "create" 
            but also drops tables when Hibernate closes; value="validate" makes no changes 
            to the database -->
        <property name="hibernate.hbm2ddl.auto" value="create" />
        <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy" />
        <property name="hibernate.connection.charSet" value="UTF-8" />
        <!-- Uncomment the following two properties for JBoss only -->
        <property name="hibernate.validator.apply_to_ddl" value="false" />
        <property name="hibernate.validator.autoregister_listeners"
            value="false" />
    </properties>
</persistence-unit>


META-INF / JBoss的部署-structure.xml

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
    <deployment>
        <exclusions>
            <module name="org.hibernate" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>

JBOSS server.log

17:49:54,841 INFO  [org.springframework.web.context.ContextLoader] (MSC service thread 1-2) Root WebApplicationContext: initialization started
17:49:54,898 INFO  [org.springframework.web.context.support.XmlWebApplicationContext] (MSC service thread 1-2) Refreshing Root WebApplicationContext: startup date [Fri Feb 08 17:49:54 EST 2013]; root of context hierarchy
17:49:55,027 INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (MSC service thread 1-2) Loading XML bean definitions from "/C:/jboss-as-7.1.1.Final/bin/content/lmis.war/WEB-INF/classes/META-INF/spring/applicationContext-jpa.xml"
17:49:56,011 INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (MSC service thread 1-2) Loading XML bean definitions from "/C:/jboss-as-7.1.1.Final/bin/content/lmis.war/WEB-INF/classes/META-INF/spring/applicationContext-security.xml"
17:49:56,174 INFO  [org.springframework.security.core.SpringSecurityCoreVersion] (MSC service thread 1-2) You are running with Spring Security Core 3.1.0.RELEASE
17:49:56,177 INFO  [org.springframework.security.config.SecurityNamespaceHandler] (MSC service thread 1-2) Spring Security 'config' module version is 3.1.0.RELEASE
17:49:56,219 INFO  [org.springframework.security.config.http.FilterInvocationSecurityMetadataSourceParser] (MSC service thread 1-2) Creating access control expression attribute 'hasRole('ROLE_ADMIN')' for /choices/**
17:49:56,222 INFO  [org.springframework.security.config.http.FilterInvocationSecurityMetadataSourceParser] (MSC service thread 1-2) Creating access control expression attribute 'isAuthenticated()' for /member/**
17:49:56,224 INFO  [org.springframework.security.config.http.FilterInvocationSecurityMetadataSourceParser] (MSC service thread 1-2) Creating access control expression attribute 'permitAll' for /resources/**
17:49:56,226 INFO  [org.springframework.security.config.http.FilterInvocationSecurityMetadataSourceParser] (MSC service thread 1-2) Creating access control expression attribute 'permitAll' for /**
17:49:56,245 INFO  [org.springframework.security.config.http.HttpSecurityBeanDefinitionParser] (MSC service thread 1-2) Checking sorted filter chain: [Root bean: class [org.springframework.security.web.context.SecurityContextPersistenceFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 300, Root bean: class [org.springframework.security.web.authentication.logout.LogoutFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 400, <org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0>, order = 800, Root bean: class [org.springframework.security.web.authentication.www.BasicAuthenticationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1200, Root bean: class [org.springframework.security.web.savedrequest.RequestCacheAwareFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1300, Root bean: class [org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1400, Root bean: class [org.springframework.security.web.authentication.AnonymousAuthenticationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1700, Root bean: class [org.springframework.security.web.session.SessionManagementFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1800, Root bean: class [org.springframework.security.web.access.ExceptionTranslationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1900, <org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0>, order = 2000]
17:49:56,275 INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (MSC service thread 1-2) Loading XML bean definitions from "/C:/jboss-as-7.1.1.Final/bin/content/lmis.war/WEB-INF/classes/META-INF/spring/applicationContext.xml"
17:49:56,308 INFO  [org.springframework.context.annotation.ClassPathBeanDefinitionScanner] (MSC service thread 1-2) JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
17:49:56,311 INFO  [org.springframework.context.annotation.ClassPathBeanDefinitionScanner] (MSC service thread 1-2) JSR-330 'javax.inject.Named' annotation found and supported for component scanning
17:49:57,479 INFO  [org.springframework.context.support.PropertySourcesPlaceholderConfigurer] (MSC service thread 1-2) Loading properties file from "/C:/jboss-as-7.1.1.Final/bin/content/lmis.war/WEB-INF/classes/META-INF/spring/database.properties"
17:49:57,496 INFO  [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (MSC service thread 1-2) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
17:49:57,603 INFO  [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] (MSC service thread 1-2) Building JPA container EntityManagerFactory for persistence unit 'jpaHibernatePersistenceUnit'
17:49:57,775 INFO  [org.hibernate.annotations.common.Version] (MSC service thread 1-2) HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
17:49:57,780 INFO  [org.hibernate.Version] (MSC service thread 1-2) HHH000412: Hibernate Core {4.1.8.Final}
17:49:57,784 INFO  [org.hibernate.cfg.Environment] (MSC service thread 1-2) HHH000206: hibernate.properties not found
17:49:57,786 INFO  [org.hibernate.cfg.Environment] (MSC service thread 1-2) HHH000021: Bytecode provider name : javassist
17:49:57,804 INFO  [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-2) HHH000204: Processing PersistenceUnitInfo [
    name: jpaHibernatePersistenceUnit
    ...]
17:49:57,913 INFO  [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] (MSC service thread 1-2) HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
17:49:58,383 INFO  [org.hibernate.dialect.Dialect] (MSC service thread 1-2) HHH000400: Using dialect: org.hibernate.dialect.SQLServerDialect
17:49:58,393 INFO  [org.hibernate.engine.jdbc.internal.LobCreatorBuilder] (MSC service thread 1-2) HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
17:49:58,403 INFO  [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (MSC service thread 1-2) HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
17:49:58,407 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (MSC service thread 1-2) HHH000397: Using ASTQueryTranslatorFactory
17:49:58,463 INFO  [org.hibernate.validator.util.Version] (MSC service thread 1-2) Hibernate Validator 4.2.0.Final
17:49:58,507 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-2) HHH000227: Running hbm2ddl schema export
17:49:58,511 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-2) HHH000230: Schema export complete
17:49:58,543 INFO  [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-2) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@14f0e813: defining beans [dataSource,transactionManager,entityManagerFactory,org.springframework.security.filterChains,org.springframework.security.filterChainProxy,org.springframework.security.web.PortMapperImpl#0,org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0,org.springframework.security.authentication.ProviderManager#0,org.springframework.security.web.context.HttpSessionSecurityContextRepository#0,org.springframework.security.web.authentication.session.SessionFixationProtectionStrategy#0,org.springframework.security.web.savedrequest.HttpSessionRequestCache#0,org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler#0,org.springframework.security.access.vote.AffirmativeBased#0,org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0,org.springframework.security.web.access.DefaultWebInvocationPrivilegeEvaluator#0,org.springframework.security.authentication.AnonymousAuthenticationProvider#0,org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint#0,org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0,org.springframework.security.userDetailsServiceFactory,org.springframework.security.web.DefaultSecurityFilterChain#0,org.springframework.security.provisioning.InMemoryUserDetailsManager#0,org.springframework.security.authentication.dao.DaoAuthenticationProvider#0,org.springframework.security.authentication.DefaultAuthenticationEventPublisher#0,org.springframework.security.authenticationManager,org.springframework.context.support.PropertySourcesPlaceholderConfigurer#0,org.springframework.context.config.internalBeanConfigurerAspect,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.transaction.config.internalTransactionAspect,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
17:49:58,825 INFO  [org.springframework.security.web.DefaultSecurityFilterChain] (MSC service thread 1-2) Creating filter chain: org.springframework.security.web.util.AnyRequestMatcher@1, [org.springframework.security.web.context.SecurityContextPersistenceFilter@2f7d54e1, org.springframework.security.web.authentication.logout.LogoutFilter@4d4f9822, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@248d07d5, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@26fd43b2, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@3d676f1d, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@51aff869, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@77dddf64, org.springframework.security.web.session.SessionManagementFilter@7755bb7, org.springframework.security.web.access.ExceptionTranslationFilter@29d84f34, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@3837f462]
17:49:58,858 INFO  [org.springframework.security.config.http.DefaultFilterChainValidator] (MSC service thread 1-2) Checking whether login URL '/login' is accessible with your configuration
17:49:58,999 INFO  [org.springframework.web.context.ContextLoader] (MSC service thread 1-2) Root WebApplicationContext: initialization completed in 4156 ms
17:49:59,334 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/lmis]] (MSC service thread 1-2) Initializing Spring FrameworkServlet 'lmis'
17:49:59,337 INFO  [org.springframework.web.servlet.DispatcherServlet] (MSC service thread 1-2) FrameworkServlet 'lmis': initialization started
17:49:59,342 INFO  [org.springframework.web.context.support.XmlWebApplicationContext] (MSC service thread 1-2) Refreshing WebApplicationContext for namespace 'lmis-servlet': startup date [Fri Feb 08 17:49:59 EST 2013]; parent: Root WebApplicationContext
17:49:59,347 INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (MSC service thread 1-2) Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/webmvc-config.xml]
17:49:59,930 INFO  [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (MSC service thread 1-2) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
17:49:59,942 INFO  [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-2) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@62f314a8: defining beans [assignedCertificationController,certificationController,certificationSourceController,courseController,courseSeriesController,courseSeriesTemplateController,courseTemplateController,employeeController,jobCertificationGroupController,manualCertificationGroupController,qualificationController,qualificationLogController,titleCertificationGroupController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,mvcContentNegotiationManager,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0,org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#0,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#1,org.springframework.web.servlet.handler.MappedInterceptor#1,org.springframework.web.servlet.handler.MappedInterceptor#2,org.springframework.web.servlet.config.viewControllerHandlerMapping,messageSource,localeResolver,themeSource,themeResolver,org.springframework.web.servlet.handler.SimpleMappingExceptionResolver#0,multipartResolver,tilesViewResolver,tilesConfigurer,applicationConversionService,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@14f0e813
17:50:00,147 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-2) Mapped "{[/assignedcertifications],methods=[],params=[],headers=[],consumes=[],produces=[text/html],custom=[]}" onto public java.lang.String com.lmco.lmis.web.AssignedCertificationController.list(java.lang.Integer,java.lang.Integer,org.springframework.ui.Model)

2 个答案:

答案 0 :(得分:0)

实际上, jboss-deployment-structure.xml jpaVendorAdapter 属性没有必要。 但是您应该在持久性单元中添加实体类列表。 说明和示例位于JBoss documentation

At-leaset,对我有用

答案 1 :(得分:0)

直到版本4.2的独立Hibernate在JBoss中运行时无法扫描实体。

负责扫描org.hibernate.ejb.packaging.JarVisitorFactory的类不处理JBoss VFS协议。

可能的解决方法是使用Spring(> 3.1.x)进行扫描。类org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean的属性packagesToScan可以设置为com.company.**.*

注意:Hibernate 4.3在新软件包org.hibernate.jpa.boot.scan中重新设计扫描,我没有尝试过这个版本。