2012-06-27 66 views
0
Error occurred during deployment: Exception while loading the app : 
java.lang.IllegalStateException: ContainerBase.addChild: start: 
org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: 
java.lang.IncompatibleClassChangeError: Implementing class. Please see server.log for more details. 

org.springframework.beans.factory.BeanCreationException: 
    Error creating bean with name 'helloWorldController': 
    Injection of autowired dependencies failed; nested exception is 
org.springframework.beans.factory.BeanCreationException: 
    Could not autowire field: private org.hibernate.SessionFactory 
    org.meluk.billboard.business.controller.HelloWorldController.sessionFactory; nested exception is 
org.springframework.beans.factory.BeanCreationException: 
    Error creating bean with name 'sessionFactory' defined in 
    ServletContext resource [/WEB-INF/billboard-servlet.xml]: 
    Invocation of init method failed; nested exception is 
    java.lang.IncompatibleClassChangeError: Implementing class 

我的pom.xml:IncompatibleClassChangeError而Spring上下文初始化

<properties> 
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <springVersion>3.1.0.RELEASE</springVersion> 
    <hibernateVersion>3.5.4-Final</hibernateVersion> 
    <junitVersion>4.8.2</junitVersion> 
</properties> 

<dependencyManagement> 
    <dependencies> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-context</artifactId> 
      <version>${springVersion}</version> 
     </dependency> 
    </dependencies> 
</dependencyManagement> 

<dependencies> 
    <dependency> 
     <groupId>javax.sql</groupId> 
     <artifactId>jdbc-stdext</artifactId> 
     <version>2.0</version> 
    </dependency> 

    <dependency> 
     <groupId>javax</groupId> 
     <artifactId>javaee-web-api</artifactId> 
     <version>6.0</version> 
     <scope>provided</scope> 
    </dependency> 

    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>${junitVersion}</version> 
     <scope>test</scope> 
    </dependency> 

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


    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-orm</artifactId> 
     <version>${springVersion}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-hibernate3</artifactId> 
     <version>2.0.8</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-webmvc</artifactId> 
     <version>${springVersion}</version> 
    </dependency> 

我的Spring配置文件:

<context:component-scan base-package="org.meluk.billboard.business.controller" /> 
<tx:annotation-driven transaction-manager="txManager" /> 
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <property name="locations"> 
     <list> 
      <value>/WEB-INF/config/jdbc.properties</value> 
     </list> 
    </property> 
</bean> 

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" > 
    <property name="driverClassName" value="${hibernate.connection.driver_class}" /> 
    <property name="url" value="${hibernate.connection.url}" /> 
    <property name="username" value="${hibernate.connection.username}" /> 
    <property name="password" value="${hibernate.connection.password}" /> 
</bean> 
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
    <property name="dataSource" ref="dataSource" /> 
    <property name="configLocation" value="/WEB-INF/hibernate.cfg.xml" /> 
    <property name="hibernateProperties"> 
     <props> 
      <prop key="hibernate.dialect">${hibernate.dialect}</prop> 
      <prop key="hibernate.default_schema">${hibernate.default_schema}</prop> 
      <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> 
      <prop key="hibernate.c3p0.min_size">${hibernate.c3p0.min_size}</prop> 
      <prop key="hibernate.c3p0.max_size">${hibernate.c3p0.max_size}</prop> 
      <prop key="hibernate.c3p0.timeout">${hibernate.c3p0.timeout}</prop> 
      <prop key="hibernate.c3p0.max_statements">${hibernate.c3p0.max_statements}</prop> 
     </props> 
    </property> 
</bean> 


<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
    <property name="sessionFactory" ref="sessionFactory" /> 
</bean> 

請幫助解決這個問題。

回答

2

明確設置彈簧Hibernate3的依賴性:

<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-hibernate3</artifactId> 
<version>2.0.8</version> 

這不是巧合,這是你得到的例外豆。

你不應該這樣做;你有沒有使用Spring的同一版本的spring-orm的原因?我有一段時間沒有設置明確的hibernate3依賴關係。

+0

2.0.8是最新的可用版本.http://mvnrepository.com/artifact/org.springframework/spring-hibernate3 – Balconsky

+0

@Balconsky是什麼讓你覺得你需要它? –

2

IncompatibleClassChangeError意味着JVM獲得有關某個類的相互矛盾的信息。當您針對一個類或接口的某個版本編譯某些代碼時,通常會發生這種情況,但在運行時使用該類/接口的不同版本。當JVM檢查類和方法簽名匹配時,運行時就會遇到問題。

在這種情況下,「實現類」消息似乎是說改變的類不再實現它原來的一些接口。 (也許程序包名稱已更改)

在日誌文件的某處應該有一個消息,指出導致問題的類,但是您提供的堆棧跟蹤的expurgated版本沒有。


我會說他們是兩種可能性。一個是,你在構建你的構建方式時遇到了問題,並且你沒有重新編譯應該重新編譯的東西。另一種可能性是你的WAR文件中有不一致的JAR混合;例如你在某種程度上混合了不同版本的Spring的JAR。

+0

如果我在WAR文件中有不一致的jar混合,我該如何識別它?哪個罐子可能不一致? – Balconsky

+0

如果你能弄清楚哪些類是衝突的,那將是一個開始。 –

相關問題