spring + hibernate entityManagerFactory / configurations / context .xml

时间:2017-05-09 14:59:48

标签: java spring hibernate spring-mvc

我找不到使用spring + hibernate工作context.xml的方法。我无法创建entityManagerFactory的{​​{1}}实例并且无法在entityManagerFactory上的context.xml声明中找到错误。

我收到此错误:

org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'entityManagerFactory' defined in PortletContext resource 
[/WEB-INF/spring/portlet-context.xml]: Invocation of init method failed;
nested exception is java.lang.IncompatibleClassChangeError: Implementing class  

下面是我的pom.xml

<properties>
    <org.slf4j-version>1.7.7</org.slf4j-version>
    <org.aspectj-version>1.8.2</org.aspectj-version>
    <liferay.maven.plugin.version>6.2.5</liferay.maven.plugin.version>
    <liferay.version>6.2.3</liferay.version>
    <spring-version>4.2.8.RELEASE</spring-version> 
    <hibernate.version>4.3.11.Final</hibernate.version>
    <java-version>1.8</java-version>
    <portlet-api.version>2.0</portlet-api.version>
    <servlet-api.version>2.5</servlet-api.version>
    <jsp-api.version>2.2</jsp-api.version>
    <jstl.version>1.2</jstl.version>
    <liferay.auto.deploy.dir>C:\java-workspace\liferay-portal-6.2-ce-ga4\deploy</liferay.auto.deploy.dir>
    <liferay.app.server.deploy.dir>C:\java-workspace\liferay-portal-6.2-ce-ga4\tomcat-7.0.42\webapps</liferay.app.server.deploy.dir>
    <liferay.app.server.lib.global.dir>C:\java-workspace\liferay-portal-6.2-ce-ga4\tomcat-7.0.42\lib\ext</liferay.app.server.lib.global.dir>
    <liferay.app.server.portal.dir>C:\java-workspace\liferay-portal-6.2-ce-ga4\tomcat-7.0.42\webapps\ROOT</liferay.app.server.portal.dir>
</properties>


<dependency>
        <groupId>com.liferay.portal</groupId>
        <artifactId>portal-service</artifactId>
        <version>${liferay.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.liferay.portal</groupId>
        <artifactId>util-bridges</artifactId>
        <version>${liferay.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.liferay.portal</groupId>
        <artifactId>util-taglib</artifactId>
        <version>${liferay.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.liferay.portal</groupId>
        <artifactId>util-java</artifactId>
        <version>${liferay.version}</version>
        <scope>provided</scope>
    </dependency>

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

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.4</version>
    </dependency>

    <!-- Spring -->
    <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-context</artifactId>
       <version>${spring-version}</version> 
    </dependency>

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

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
   <version>${spring-version}</version> 
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
    <version>${spring-version}</version>  
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
       <version>${spring-version}</version>
    </dependency>

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

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

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




    <!-- AspectJ -->
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>${org.aspectj-version}</version>
    </dependency>

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.3.1</version>
    </dependency>

    <!-- Logging -->
    <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>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>${org.slf4j-version}</version>
        <scope>runtime</scope>
    </dependency>

    <dependency> 
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency> 

    <!-- @Inject -->
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>

    <!-- Portlet -->
    <dependency>
        <groupId>javax.portlet</groupId>
        <artifactId>portlet-api</artifactId>
        <version>${portlet-api.version}</version>
        <scope>provided</scope>
    </dependency>

    <!-- Servlet -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>${servlet-api.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>${jsp-api.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>${jstl.version}</version>
    </dependency>

这是我的上下文xml:

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xsi:schemaLocation="
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd">


<context:annotation-config />
<context:component-scan base-package="com.meera.liferay.spring.controller" /> 
<context:component-scan base-package="com.meera.liferay.spring.dao" />
<context:component-scan base-package="com.meera.liferay.spring.service" /> 
<context:component-scan base-package=" com.meera.liferay.spring.domain" />
<context:property-placeholder location="/WEB-INF/spring/spring.properties" />

 <mvc:annotation-driven />

<!-- Resolves views selected for rendering by @Controllers to .jsp resources 
    in the /WEB-INF/views directory -->
<bean id="viewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="cache" value="true" />
    <property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView" />
    <property name="prefix" value="/WEB-INF/view/" />
    <property name="suffix" value=".jsp" />
</bean>

<bean name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/liferay" />
    <property name="username" value="liferay" />
    <property name="password" value="liferay" />
</bean>

<bean id="entityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
      p:packagesToScan="com.meera.liferay.spring.domain"
      p:dataSource-ref="dataSource"
>
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="generateDdl" value="false" />
            <property name="showSql" value="false" />
        </bean>
    </property>
</bean>


<tx:annotation-driven transaction-manager="transactionManager"/>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>

<bean id="messageSource"
    class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basename" value="/WEB-INF/resources/messages" />
    <property name="defaultEncoding" value="UTF-8" />
</bean>

<bean id="localeResolver"
    class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
    <property name="defaultLocale" value="en" />
</bean>

<bean id="localeChangeInterceptor"
    class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
    <property name="paramName" value="lang" />
</bean>

<bean id="handlerMapping"
    class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
    <property name="interceptors">
        <ref bean="localeChangeInterceptor" />
    </property>
</bean>

2 个答案:

答案 0 :(得分:0)

错误说 - java.lang.IncompatibleClassChangeError实施课程

这意味着在某些点,interface已更改为abstract class或反之亦然),但实施者原始界面 已修改并重新编译以适应此(不兼容)更改。

答案 1 :(得分:0)

生活中的问题就是问题。不知道liferay有什么问题,但我删除了所有内容,并安装了新的liferay 6.2 ce,安装完成后重新启动我部署war文件并没有问题。

感谢您对此的帮助...

罗克