2

我必须升级我的项目才能开始使用 Hibernate4 和 Maven 进行构建。我有很多项目,这个过程让我因错误而死。我的项目是 Spring WebFlow、MySQL、CAS 和 Hibernate4,它使用 Hibernate3 没有任何问题。

我尽我所能制作了 pom.xml,但看起来我可能遇到了 Hibernate 版本控制问题。我收到以下错误:

NoSuchMethodException:org.hibernate.cfg.Configuration.addAnnotatedClass

我认为我的项目仍然可以尝试使用 Hibernate3 而不是 Hibernate4。如果您在下面查看我的 pom.xml,您会看到我正在请求 Hibernate4,但是如果您在打包后查看我的 WAR 文件,您可以看到 Hibernate4 和 Hibernate3 库。

这是我得到的错误:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring/database-c3p0.xml]: Invocation of init method failed; nested exception is java.lang.ExceptionInInitializerError
    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.findAutowireCandidates(DefaultListableBeanFactory.java:848)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:790)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
    ... 56 more
Caused by: java.lang.ExceptionInInitializerError
    at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:259)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
    ... 66 more
Caused by: java.lang.IllegalStateException: Expected method not found: java.lang.NoSuchMethodException: org.hibernate.cfg.Configuration.addAnnotatedClass(java.lang.Class)
    at org.springframework.util.ClassUtils.getMethod(ClassUtils.java:627)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.<clinit>(LocalSessionFactoryBuilder.java:68)
    ... 69 more
Sep 14, 2012 8:08:34 AM org.apache.catalina.core.StandardContext start

这是我的 pox.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.uftwf.schoolvisit</groupId>
    <artifactId>SchoolVisit</artifactId>
    <name>School Visit</name>
    <packaging>war</packaging>
    <version>1.0.0-BUILD-SNAPSHOT</version>

    <properties>
        <java-version>1.5</java-version>
        <springframework-version>3.1.1.RELEASE</springframework-version>
        <springwebflow-version>2.3.1.BUILD-SNAPSHOT</springwebflow-version>
        <springsecurity-version>3.1.1.RELEASE</springsecurity-version>
        <org.slf4j-version>1.5.10</org.slf4j-version>
        <hibernate.version>4.1.1.Final</hibernate.version>
    </properties>

    <dependencies>
        <!-- Spring -->

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${springframework-version}</version>
            <!-- will come with all needed Spring dependencies such as spring-core 
                and spring-beans -->
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>${springframework-version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${springframework-version}</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.webflow</groupId>
            <artifactId>spring-faces</artifactId>
            <version>${springwebflow-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>${springsecurity-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${springsecurity-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${springsecurity-version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-ldap</artifactId>
            <version>${springsecurity-version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-cas</artifactId>
            <version>${springsecurity-version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-cas-client</artifactId>
            <version>3.0.7.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>jta</artifactId>
            <version>1.1</version>
        </dependency>

        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.5</version>
        </dependency>




        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.2.2</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.21</version>
        </dependency>

        <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.1.2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.2.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.2.1</version>
            <exclusions>
                <exclusion>
                    <artifactId>commons-logging</artifactId>
                    <groupId>commons-logging</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjtools</artifactId>
            <version>1.6.2</version>
        </dependency>

        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <!-- Logging -->


        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-ext</artifactId>
            <version>${org.slf4j-version}</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${org.slf4j-version}</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${org.slf4j-version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${org.slf4j-version}</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>

        </dependency>
        <!-- JSF-303 Dependency Injection -->
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>
        <!-- Servlet -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <!-- Sun Mojarra JSF 2 runtime -->
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.1.7</version>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.1.7</version>
        </dependency>


        <!-- JSR 303 validation -->
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.0.0.GA</version>
        </dependency>

        <!-- ********************************************************************** 
            ** HIBERNATE DEPENDENCIES ** ********************************************************************** -->

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>4.0.2.GA</version>
        </dependency>



        <!-- Test -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.7</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <repositories>
        <!-- For testing against latest Spring snapshots -->
        <repository>
            <id>org.springframework.maven.snapshot</id>
            <name>Spring Maven Snapshot Repository</name>
            <url>http://maven.springframework.org/snapshot</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <!-- For developing against latest Spring milestones -->
        <repository>
            <id>org.springframework.maven.milestone</id>
            <name>Spring Maven Milestone Repository</name>
            <url>http://maven.springframework.org/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <!-- For Hibernate Validator -->
        <repository>
            <id>org.jboss.repository.releases</id>
            <name>JBoss Maven Release Repository</name>
            <url>https://repository.jboss.org/nexus/content/repositories/releases</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <!-- For Sun Mojarra JSF 2 implementation -->
        <repository>
            <id>maven2-repository.dev.java.net</id>
            <name>Java.net Repository for Maven</name>
            <url>http://download.java.net/maven/2/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <!-- For PrimeFaces JSF component library -->

    </repositories>

    <build>
        <finalName>SchoolVisit</finalName>
    </build>
</project>

这是来自 maven 的 WAR 中我的 lib 中的文件列表:

activation-1.1.jar
antlr-2.7.6.jar
antlr-2.7.7.jar
aopalliance-1.0.jar
asm-3.1.jar
asm-3.3.1.jar
asm-attrs-1.5.3.jar
aspectjrt-1.6.8.jar
aspectjtools-1.6.2.jar
aspectjweaver-1.6.8.jar
c3p0-0.9.1.2.jar
c3p0-0.9.2-pre4.jar
cal10n-api-0.7.2.jar
cas-client-core-3.1.10.jar
cas-client-core-3.1.12.jar
cas-client-core-3.2.1.jar
cglib-2.2.2.jar
cglib-2.2.jar
commons-beanutils-1.8.0.jar
commons-codec-1.4.jar
commons-codec-1.6.jar
commons-collections-3.1.jar
commons-dbcp.jar
commons-digester-1.8.1.jar
commons-email-1.0.jar
commons-fileupload-1.1.1.jar
commons-io-1.1.jar
commons-lang-2.5.jar
commons-logging-1.1.1.jar
commons-pool.jar
dom4j-1.6.1.jar
dumbster-1.6.jar
ehcache-1.2.3.jar
hibernate-annotations-3.5.0-Final.jar
hibernate-commons-annotations-3.2.0.Final.jar
hibernate-commons-annotations-4.0.1.Final.jar
hibernate-core-3.5.0-Final.jar
hibernate-core-4.1.1.Final.jar
hibernate-entitymanager-3.5.0-Final.jar
hibernate-entitymanager-4.1.1.Final.jar
hibernate-jpa-2.0-api-1.0.0.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
hibernate-search-3.0.0.GA.jar
hibernate-validator-4.0.2.GA.jar
hsqldb-1.8.0.10.jar
httpclient-4.1.2.jar
httpclient-4.2.1.jar
httpclient-cache-4.1.2.jar
httpcore-4.1.2.jar
httpcore-4.2.1.jar
httpmime-4.1.2.jar
icu4j-2.6.1.jar
jackson-core-asl-1.5.3.jar
jackson-mapper-asl-1.5.3.jar
javassist-3.15.0-GA.jar
javassist-3.9.0.GA.jar
javax.inject-1.jar
javax.servlet-jstl-1.2.jar
jaxb-api-2.1.jar
jaxb-impl-2.1.3.jar
jaxen-1.1.1.jar
jboss-logging-3.1.0.GA.jar
jboss-transaction-api_1.1_spec-1.0.0.Final.jar
jcl-over-slf4j-1.5.10.jar
jdom-1.0.jar
joda-time-1.6.jar
joda-time-jsptags-1.0.2.jar
jsf-api-2.1.7.jar
jsf-impl-2.1.7.jar
jstl-1.2.jar
jstl-jstl-1.2.jar
jta-1.1.jar
list.txt
log4j-1.2.14.jar
log4j-1.2.15.jar
log4j-1.2.16.jar
lucene-core-2.3.2.jar
lucene-highlighter-2.0.0.jar
mail-1.4.5.jar
mail-1.4.jar
mailapi.jar
mail.jar
mchange-commons-java-0.2.2.jar
mysql-connector-java-5.0.5.jar
mysql-connector-java-5.1.21.jar
org.springframework.aop-3.1.1.RELEASE.jar
org.springframework.asm-3.1.1.RELEASE.jar
org.springframework.aspects-3.1.1.RELEASE.jar
org.springframework.beans-3.1.1.RELEASE.jar
org.springframework.binding-2.3.1.RELEASE.jar
org.springframework.context-3.1.1.RELEASE.jar
org.springframework.context.support-3.1.1.RELEASE.jar
org.springframework.core-3.1.1.RELEASE.jar
org.springframework.expression-3.1.1.RELEASE.jar
org.springframework.faces-2.3.1.RELEASE.jar
org.springframework.instrument-3.1.1.RELEASE.jar
org.springframework.instrument.tomcat-3.1.1.RELEASE.jar
org.springframework.jdbc-3.1.1.RELEASE.jar
org.springframework.jms-3.1.1.RELEASE.jar
org.springframework.js-2.3.1.RELEASE.jar
org.springframework.js.resources-2.3.1.RELEASE.jar
org.springframework.orm-3.1.1.RELEASE.jar
org.springframework.oxm-3.1.1.RELEASE.jar
org.springframework.test-3.1.1.RELEASE.jar
org.springframework.transaction-3.1.1.RELEASE.jar
org.springframework.web-3.1.1.RELEASE.jar
org.springframework.webflow-2.3.1.RELEASE.jar
org.springframework.web.portlet-3.1.1.RELEASE.jar
org.springframework.web.servlet-3.1.1.RELEASE.jar
org.springframework.web.struts-3.1.1.RELEASE.jar
persistence-api-1.0.jar
quartz-1.5.2.jar
slf4j-api-1.5.10.jar
slf4j-ext-1.5.10.jar
slf4j-log4j12-1.5.10.jar
smtp.jar
spring-aop-3.0.7.RELEASE.jar
spring-asm-3.1.1.RELEASE.jar
spring-aspects-3.1.1.RELEASE.jar
spring-beans-3.1.1.RELEASE.jar
spring-binding-2.3.1.BUILD-20120326.222602-13.jar
spring-context-3.1.1.RELEASE.jar
spring-context-support-3.1.1.RELEASE.jar
spring-core-3.1.1.RELEASE.jar
spring-expression-3.1.1.RELEASE.jar
spring-faces-2.3.1.BUILD-20120326.222626-13.jar
spring-jdbc-3.1.1.RELEASE.jar
spring-js-2.3.1.BUILD-20120326.222614-13.jar
spring-js-resources-2.3.1.BUILD-20120326.222607-13.jar
spring-ldap-1.3.1.RELEASE-all.jar
spring-ldap-core-1.3.1.RELEASE.jar
spring-orm-3.1.1.RELEASE.jar
spring-security-cas-3.1.0.RELEASE.jar
spring-security-cas-3.1.1.RELEASE.jar
spring-security-cas-client-3.0.7.RELEASE.jar
spring-security-config-3.1.0.RELEASE.jar
spring-security-config-3.1.1.RELEASE.jar
spring-security-core-3.1.0.RELEASE.jar
spring-security-core-3.1.1.RELEASE.jar
spring-security-crypto-3.1.0.RELEASE.jar
spring-security-ldap-3.1.0.RELEASE.jar
spring-security-ldap-3.1.1.RELEASE.jar
spring-security-openid-3.1.0.RELEASE.jar
spring-security-remoting-3.1.0.RELEASE.jar
spring-security-taglibs-3.1.0.RELEASE.jar
spring-security-web-3.1.0.RELEASE.jar
spring-security-web-3.1.1.RELEASE.jar
spring-tx-3.0.5.RELEASE.jar
spring-tx-3.1.1.RELEASE.jar
spring-web-3.1.1.RELEASE.jar
spring-webflow-2.3.1.BUILD-20120326.222621-13.jar
spring-webmvc-3.1.1.RELEASE.jar
stax-api-1.0-2.jar
tiles-api-2.1.3.jar
tiles-core-2.1.3.jar
tiles-jsp-2.1.3.jar
tiles-servlet-2.1.3.jar
urlrewritefilter-3.1.0.jar
validation-api-1.0.0.GA.jar
xalan-2.6.0.jar
xml-apis-1.0.b2.jar
xml-apis-1.3.02.jar
xmlParserAPIs-2.6.2.jar
xom-1.0.jar

如您所见,我的 POM.XML 正在导入同一文件的多个版本,我认为这可能是问题,但我不知道。作为 Maven 和 Hibernate4 的新手,我不知道真正的问题。期待听到一些反馈...谢谢

这是我的 mvn 依赖项的输出:tree 但我仍然看不到 Hibernate3 的来源:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building School Visit 1.0.0-BUILD-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ SchoolVisit ---
[INFO] org.uftwf.schoolvisit:SchoolVisit:war:1.0.0-BUILD-SNAPSHOT
[INFO] +- org.springframework:spring-orm:jar:3.1.1.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:3.1.1.RELEASE:compile
[INFO] |  +- org.springframework:spring-core:jar:3.1.1.RELEASE:compile
[INFO] |  +- org.springframework:spring-jdbc:jar:3.1.1.RELEASE:compile
[INFO] |  \- org.springframework:spring-tx:jar:3.1.1.RELEASE:compile
[INFO] +- org.springframework:spring-aspects:jar:3.1.1.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:3.1.1.RELEASE:compile
[INFO] |  \- org.springframework:spring-context-support:jar:3.1.1.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:3.1.1.RELEASE:compile
[INFO] |  +- org.springframework:spring-asm:jar:3.1.1.RELEASE:compile
[INFO] |  +- org.springframework:spring-expression:jar:3.1.1.RELEASE:compile
[INFO] |  \- org.springframework:spring-web:jar:3.1.1.RELEASE:compile
[INFO] +- org.springframework.webflow:spring-faces:jar:2.3.1.BUILD-SNAPSHOT:compile
[INFO] |  +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] |  +- org.springframework.webflow:spring-binding:jar:2.3.1.BUILD-SNAPSHOT:compile
[INFO] |  +- org.springframework.webflow:spring-js:jar:2.3.1.BUILD-SNAPSHOT:compile
[INFO] |  |  \- org.springframework.webflow:spring-js-resources:jar:2.3.1.BUILD-SNAPSHOT:compile
[INFO] |  \- org.springframework.webflow:spring-webflow:jar:2.3.1.BUILD-SNAPSHOT:compile
[INFO] +- org.springframework.security:spring-security-core:jar:3.1.1.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:3.0.7.RELEASE:compile
[INFO] |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- org.springframework.security:spring-security-config:jar:3.1.1.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-web:jar:3.1.1.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-ldap:jar:3.1.1.RELEASE:compile
[INFO] |  \- org.springframework.ldap:spring-ldap-core:jar:1.3.1.RELEASE:compile
[INFO] |     \- commons-lang:commons-lang:jar:2.5:compile
[INFO] +- org.springframework.security:spring-security-cas:jar:3.1.1.RELEASE:compile
[INFO] |  \- org.jasig.cas.client:cas-client-core:jar:3.1.12:compile
[INFO] +- org.springframework.security:spring-security-cas-client:jar:3.0.7.RELEASE:compile
[INFO] |  \- org.jasig.cas:cas-client-core:jar:3.1.10:compile
[INFO] +- javax.transaction:jta:jar:1.1:compile
[INFO] +- javax.mail:mail:jar:1.4.5:compile
[INFO] |  \- javax.activation:activation:jar:1.1:compile
[INFO] +- cglib:cglib:jar:2.2.2:compile
[INFO] |  \- asm:asm:jar:3.3.1:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.21:compile
[INFO] +- c3p0:c3p0:jar:0.9.1.2:compile
[INFO] +- org.apache.httpcomponents:httpcore:jar:4.2.1:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.2.1:compile
[INFO] |  \- commons-codec:commons-codec:jar:1.6:compile
[INFO] +- org.aspectj:aspectjtools:jar:1.6.2:compile
[INFO] +- jstl:jstl:jar:1.2:compile
[INFO] +- org.slf4j:slf4j-ext:jar:1.5.10:compile
[INFO] |  \- ch.qos.cal10n:cal10n-api:jar:0.7.2:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.5.10:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.5.10:compile
[INFO] +- org.slf4j:jcl-over-slf4j:jar:1.5.10:compile
[INFO] +- log4j:log4j:jar:1.2.16:compile
[INFO] +- javax.inject:javax.inject:jar:1:compile
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- javax.servlet.jsp:jsp-api:jar:2.1:provided
[INFO] +- javax.servlet:jstl:jar:1.2:compile
[INFO] +- com.sun.faces:jsf-api:jar:2.1.7:compile
[INFO] +- com.sun.faces:jsf-impl:jar:2.1.7:compile
[INFO] +- javax.validation:validation-api:jar:1.0.0.GA:compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:4.1.1.Final:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.1.0.GA:compile
[INFO] |  +- org.hibernate:hibernate-core:jar:4.1.1.Final:compile
[INFO] |  |  \- antlr:antlr:jar:2.7.7:compile
[INFO] |  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.0.Final:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
[INFO] |  +- org.javassist:javassist:jar:3.15.0-GA:compile
[INFO] |  \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile
[INFO] +- org.hibernate:hibernate-validator:jar:4.0.2.GA:compile
[INFO] |  +- javax.xml.bind:jaxb-api:jar:2.1:compile
[INFO] |  |  \- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] |  \- com.sun.xml.bind:jaxb-impl:jar:2.1.3:compile
[INFO] \- junit:junit:jar:4.7:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.291s
[INFO] Finished at: Fri Sep 14 09:06:33 EDT 2012
[INFO] Final Memory: 11M/162M
[INFO] ------------------------------------------------------------------------
4

3 回答 3

2

我修好了它。我创建了一个新的 maven webapp 并复制到 pom.xml 和源代码中,一切都很棒......

于 2012-09-14T14:49:12.287 回答
0

解决此类问题的典型方法是运行mvn dependency:tree -Dverbose并分析其输出,以找出错误版本的依赖项来自何处,然后通过应用必要的排除来修复它们。

但是,在您的情况下,输出mvn dependency:tree不包含任何错误。因此,我认为您的target文件夹中有旧版本的依赖项,因此您需要运行mvn clean以删除它们。

于 2012-09-14T12:42:20.910 回答
0

正如其他人所指出的,运行“mvn dependency:tree”以查看从何处获取 hibernate 3 依赖项。然后您可以在 pom.xml 中排除它:

<dependency>
    <exclusions>
        <exclusion>
           <groupId>org.hibernate</groupId>           
        </exclusion>
    </exclusions>
</dependency>

从 hibernate 3 到 4 还需要从 hibernate3 包中的 AnnotationSessionFactoryBean 更改为 hibernate4 包中的 LocalSessionFactoryBean,并使用 hibernate4 包中的事务管理器。

曾经在 hibernate3 包中的两个单独的 bean(本地和注释)现在变成了 hibernate4 包中的一个 bean,如果你升级了你就不能使用 hibernate3 包。

http://blog.springsource.org/2012/04/06/migrating-to-spring-3-1-and-hibernate-4-1/

于 2012-09-14T13:03:45.627 回答