返回顶部
首页 > 资讯 > 数据库 >LocalContainerEntityManagerFactoryBean spring
  • 421
分享到

LocalContainerEntityManagerFactoryBean spring

2024-04-02 19:04:59 421人浏览 八月长安
摘要

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappinGConte

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappinGContext': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined 

搭建的环境折腾了很久,以后遇到这种类似问题,原来是这个原因,已经哭晕






报错现象:


javax.servlet.ServletException: Servlet.init() for servlet mvc-dispatcher threw exception
	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
	org.apache.coyote.Http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085)
	org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
	org.apache.coyote.http11.Http11NIOProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
	org.apache.Tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556)
	org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513)
	java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	java.lang.Thread.run(Thread.java:745)

root cause

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'packagesToScan' of bean class [org.springframework.ORM.jpa.LocalEntityManagerFactoryBean]: Bean property 'packagesToScan' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
	org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	org.springframework.beans.factory.support.DefaultSingletonBeanReGIStry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:753)
	org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
	org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
	org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:666)
	org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:632)
	org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:680)
	org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:551)
	org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:492)
	org.springframework.web.servlet.httpservletBean.init(HttpServletBean.java:136)
	javax.servlet.GenericServlet.init(GenericServlet.java:158)
	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
	org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085)
	org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
	org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
	org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556)
	org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513)
	java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	java.lang.Thread.run(Thread.java:745)

root cause





结果对比:

LocalContainerEntityManagerFactoryBean  spring


环境搭建的参考文章:http://my.oschina.net/gaussik/blog/513444,总是报错,解决这个问题,搜了无数的帖子,通过对比原来是这个原因。






########################################################################################

贴上正确后的配置文件:

  1. dispatcher-servlet-mvc.xml



<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xmlns:context="http://www.springframework.org/schema/context"

       xmlns:mvc="http://www.springframework.org/schema/mvc"

       xmlns:jpa="http://www.springframework.org/schema/data/jpa"

       xmlns:tx="http://www.springframework.org/schema/tx"

       xsi:schemaLocation="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/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd

       http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd

       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">


       <!--指明 controller 所在包,并扫描其中的注解-->

       <context:component-scan base-package="com.fastdfs.controller"/>


       <!-- 静态资源(js、p_w_picpath等)的访问 -->

       <mvc:default-servlet-handler/>


       <!-- 开启注解 -->

       <mvc:annotation-driven/>


       <!--ViewResolver 视图解析器-->

       <!--用于支持Servlet、JSP视图解析-->

       <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">

              <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>

              <property name="prefix" value="/WEB-INF/pages/"/>

              <property name="suffix" value=".jsp"/>

       </bean>



       <!--使用Spring的CommonsMultipartResolver上传文件-->


       <bean

               id="multipartResolver"

               class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

              <property name="defaultEncoding" value="UTF-8"/>

              <!-- one of the properties available; the maximum file size in bytes -->

              <property name="maxUploadSize" value="100000000"/>


       </bean>





       <!-- 表示JPA Repository所在的包 -->

       <jpa:repositories base-package="com.fastdfs.repository"/>


       <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

              <property name="persistenceUnitName" value="FastDFSPersistenceUnit"/>

              <property name="packagesToScan" value="com.fastdfs.model" />

              <property name="jpaVendorAdapter">

                     <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>

              </property>

              <property name="jpaProperties">

                     <props>

                            <prop key="hibernate.connection.driver_class">com.Mysql.jdbc.Driver</prop>

                            <prop key="hibernate.connection.url">jdbc:mysql://192.168.200.33:3306/fastdfs?useSSL=false</prop>

                            <prop key="hibernate.connection.username">adminuser</prop>

                            <prop key="hibernate.connection.passWord">localadmin2015!</prop>

                            <prop key="hibernate.show_sql">false</prop>

                            <prop key="hibernate.connection.useUnicode">true</prop>

                            <prop key="hibernate.connection.characterEncoding">UTF-8</prop>

                            <prop key="hibernate.format_sql">true</prop>

                            <prop key="hibernate.use_sql_comments">true</prop>

                            <prop key="hibernate.hbm2ddl.auto">update</prop>

                            <prop key="hibernate.connection.autoReconnect">true</prop>

                            <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>

                            <prop key="connection.autoReconnectForPools">true</prop>

                            <prop key="connection.is-connection-validation-required">true</prop>


                            <prop key="hibernate.c3p0.validate">true</prop>

                            <prop key="hibernate.connection.provider_class">org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider</prop>

                            <prop key="hibernate.c3p0.min_size">5</prop>

                            <prop key="hibernate.c3p0.max_size">600</prop>

                            <prop key="hibernate.c3p0.timeout">1800</prop>

                            <prop key="hibernate.c3p0.max_statements">50</prop>

                            <prop key="hibernate.c3p0.preferredTestQuery">SELECT 1;</prop>

                            <prop key="hibernate.c3p0.testConnectionOnCheckout">true</prop>

                            <prop key="hibernate.c3p0.idle_test_period">3000</prop>


                     </props>

              </property>

       </bean>


       <!-- 事务管理 -->

       <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">

              <property name="entityManagerFactory" ref="entityManagerFactory"/>

       </bean>


       <!-- 开启事务管理注解 -->

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

</beans>








########################################################################################

2.persistences.xml



<?xml version="1.0" encoding="UTF-8"?>

        <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

            <persistence-unit name="FastDFSPersistenceUnit" transaction-type="RESOURCE_LOCAL">

                <provider>org.hibernate.ejb.HibernatePersistence</provider>



    <properties>


    <!-- 使用MySQL方言 -->

    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>

    <!-- 数据库连接的URL地址 -->

    <property name="hibernate.connection.url"

              value="jdbc:mysql://192.168.200.33:3306/fastdfs"/>

    <!-- 数据库连接的驱动 -->

    <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>

    <!-- 数据库连接的用户名 -->

    <property name="hibernate.connection.username"  value="****"  />

    <!-- 数据库连接的密码 -->

    <property name="hibernate.connection.password" value="******"/>

    <!-- 显示SQL语句 -->

    <property name="hibernate.show_sql" value="true"/>


    <property name="hibernate.connection.useUnicode" value="true"/>

    <property name="hibernate.connection.characterEncoding" value="UTF-8"/>


    <!-- 在显示SQL语句时格式化语句 -->

    <property name="hibernate.format_sql" value="true"/>

    <property name="hibernate.use_sql_comments" value="false"/>

    <!-- 自动输出schema创建DDL语句 -->

    <property name="hibernate.hbm2ddl.auto" value="update"/>


    <!-- 数据库连接超时后自动重连 -->

    <property name="hibernate.connection.autoReconnect" value="true"/>

    <property name="connection.autoReconnectForPools" value="true"/>

    <property name="connection.is-connection-validation-required" value="true"/>


    </properties>


    </persistence-unit>

</persistence>

########################################################################################





项目已经跑通,fastdfs+springMVC+ spring data jpa +hibernate +fastdfs java api 


您可能感兴趣的文档:

--结束END--

本文标题: LocalContainerEntityManagerFactoryBean spring

本文链接: https://lsjlt.com/news/40497.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作