中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

LocalContainerEntityManagerFactoryBean spring

發布時間:2020-07-08 16:32:21 來源:網絡 閱讀:6573 作者:TIMES2020 欄目:數據庫

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 


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

百色市| 乐都县| 钦州市| 出国| 甘肃省| 宜昌市| 突泉县| 海兴县| 察隅县| 胶州市| 武乡县| 大悟县| 育儿| 南昌市| 海晏县| 道真| 建宁县| 高雄市| 榆树市| 汝州市| 城口县| 白水县| 湾仔区| 凌海市| 普陀区| 清苑县| 敖汉旗| 新河县| 广南县| 龙陵县| 沾化县| 明水县| 房产| 丰都县| 定陶县| 故城县| 梁河县| 商水县| 手游| 兴业县| 黔西|