0

我认为在我的项目中添加一些测试是个好主意,但在这个过程中,我不知何故设法让真正的交易破裂。

我正在使用带有 JPA(休眠)的 Spring MVC。entityManager 无法再正确加载:

INFO - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3aa1e2da: defining beans [dataSource,org.springframework.context.support.PropertySourcesPlaceholderConfigurer#0,signatureBlobService,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#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,validator,emf,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]; root of factory hierarchy
INFO - Hibernate Validator 4.2.0.Final
INFO - Building JPA container EntityManagerFactory for persistence unit 'default'
INFO - HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
INFO - HHH000412: Hibernate Core {4.1.4.Final}
INFO - HHH000206: hibernate.properties not found
INFO - HHH000021: Bytecode provider name : javassist
INFO - HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
INFO - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3aa1e2da: defining beans [dataSource,org.springframework.context.support.PropertySourcesPlaceholderConfigurer#0,signatureBlobService,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#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,validator,emf,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]; root of factory hierarchy
ERROR - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'emf' defined in ServletContext resource [/WEB-INF/spring/root-context.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: error trying to scan <jar-file>: file:/Users/XXX/Documents/Coding/Webapps/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpwebapps/XXX/WEB-INF/classes/
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.RuntimeException: error trying to scan <jar-file>: file:/Users/david/Documents/Coding/Webapps/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpwebapps/payworkssign/WEB-INF/classes/
    at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:855)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:597)
    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:268)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
    ... 22 more
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
    at javassist.bytecode.AnnotationsAttribute.getAnnotations(AnnotationsAttribute.java:230)
    at javassist.bytecode.AnnotationsAttribute.getAnnotation(AnnotationsAttribute.java:184)
    at org.hibernate.ejb.packaging.AbstractJarVisitor.checkAnnotationMatching(AbstractJarVisitor.java:256)
    at org.hibernate.ejb.packaging.AbstractJarVisitor.executeJavaElementFilter(AbstractJarVisitor.java:212)
    at org.hibernate.ejb.packaging.AbstractJarVisitor.addElement(AbstractJarVisitor.java:173)
    at org.hibernate.ejb.packaging.ExplodedJarVisitor.getClassNamesInTree(ExplodedJarVisitor.java:126)
    at org.hibernate.ejb.packaging.ExplodedJarVisitor.getClassNamesInTree(ExplodedJarVisitor.java:134)
    at org.hibernate.ejb.packaging.ExplodedJarVisitor.getClassNamesInTree(ExplodedJarVisitor.java:134)
    at org.hibernate.ejb.packaging.ExplodedJarVisitor.getClassNamesInTree(ExplodedJarVisitor.java:134)
    at org.hibernate.ejb.packaging.ExplodedJarVisitor.getClassNamesInTree(ExplodedJarVisitor.java:134)
    at org.hibernate.ejb.packaging.ExplodedJarVisitor.doProcessElements(ExplodedJarVisitor.java:92)
    at org.hibernate.ejb.packaging.AbstractJarVisitor.getMatchingEntries(AbstractJarVisitor.java:149)
    at org.hibernate.ejb.packaging.NativeScanner.getFilesInJar(NativeScanner.java:192)
    at org.hibernate.ejb.Ejb3Configuration.addScannedEntries(Ejb3Configuration.java:504)
    at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:852)
    ... 28 more
Caused by: java.lang.NullPointerException
    at javassist.bytecode.ConstPool.getUtf8Info(ConstPool.java:616)
    at javassist.bytecode.annotation.Annotation.addMemberValue(Annotation.java:205)
    at javassist.bytecode.annotation.Annotation.addMemberValue(Annotation.java:185)
    at javassist.bytecode.AnnotationsAttribute$Parser.memberValuePair(AnnotationsAttribute.java:625)
    at javassist.bytecode.AnnotationsAttribute$Walker.memberValuePair(AnnotationsAttribute.java:355)
    at javassist.bytecode.AnnotationsAttribute$Walker.annotation(AnnotationsAttribute.java:348)
    at javassist.bytecode.AnnotationsAttribute$Parser.annotation(AnnotationsAttribute.java:620)
    at javassist.bytecode.AnnotationsAttribute$Walker.annotation(AnnotationsAttribute.java:343)
    at javassist.bytecode.AnnotationsAttribute$Parser.annotationArray(AnnotationsAttribute.java:610)
    at javassist.bytecode.AnnotationsAttribute$Walker.annotationArray(AnnotationsAttribute.java:330)
    at javassist.bytecode.AnnotationsAttribute$Walker.annotationArray(AnnotationsAttribute.java:325)
    at javassist.bytecode.AnnotationsAttribute$Parser.parseAnnotations(AnnotationsAttribute.java:588)
    at javassist.bytecode.AnnotationsAttribute.getAnnotations(AnnotationsAttribute.java:227)
    ... 42 more

跑步时

mvn test

一切都贯穿。在那里我使用嵌入式 H2 数据库删除与测试相关的东西(依赖项等)并没有解决问题。

如果我理解正确的话,Javassist 在这种情况下负责注释。我的问题是我不知道在哪里继续寻找。这真的是UTF8问题吗?为什么它试图扫描/classes目录,同时认为它是一个 jar 文件?

其他可能与该问题相关的列表:

  1. 我在 eclipse 中玩了一下项目配置(为 maven、wst 添加)。我确实再次删除了此配置以尝试是否有所作为。我也曾经mvn package war:war在本地 tomcat 上部署应用程序。同样的错误发生在这里。再次mvn test工作正常

  2. 我将 hibernate-validator 和 hibernate-entitymanager 更新到了最新版本。但是,再次降级仍然存在问题。

定位问题可能需要的其他一些信息:

我的 root-context.xml 的相关部分

<!-- Enable JPA Support -->
<!-- Enable Annotation driven declaration -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<!-- Define transaction Manager -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="emf"/>
</bean>
<bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
    </property>
    <property name="packagesToScan" value="com.payworksmobile.dev.jpa"/>
    <property name="jpaProperties">
        <props>
            <prop key="hibernate.dialect">
                org.hibernate.dialect.MySQLDialect
            </prop>
            <prop key="hibernate.max_fetch_depth">3</prop>
            <prop key="hibernate.jdbc.fetch_size">50</prop>
            <prop key="hibernate.jdbc.batch_size">10</prop>
            <prop key="hibernate.show_sql">true</prop>
        </props>
    </property>
</bean>
4

2 回答 2

0

我什至无法猜测可能是什么问题。

在这种情况下,当您不知道出了什么问题时,您可以这样做(我希望您的源代码在存储库中(svn/git 等))。

您只需将项目签出/克隆到一个新位置并构建它,看看它是否正常。您有可能没有提交破坏它的更改。

如果问题仍然存在,那么您只需返回旧版本,依此类推,直到您到达最后一个工作版本。然后,您将上一个工作版本与下一个(损坏的)版本进行比较,然后 tada!,您将首先看到导致问题的原因。

于 2012-06-20T10:06:48.300 回答
0

在发布这个问题之前尝试了很多事情之后,我实际上只是偶然发现了解决方案:

WEB-INF/classes我从我的文件夹中的测试用例中找到了两个类。这些类实际上是我的测试的配置类。删除它们后,一切都像魅力一样运行。在提取我的战争文件并从我的测试中寻找剩余部分后,我在那里找到了这些类。

为什么会这样?(这只是我的猜测)在 eclipse 中创建一个新的测试文件夹时,我花了一些时间来修改我的 pom.xml 以将此文件夹视为<testSourceDirectory>. Eclipse 在两者之间构建项目,将类文件从我的测试配置类复制到WEB-INF/classes. 这不知何故弄乱了 Spring 和 Hibernate。我的学习:检查只有相关的类被复制到战争文件中,并且 WEB-INF/classes 不包含任何剩余部分。

于 2012-06-21T06:49:35.093 回答