spring hibernate jpa spring data maven jsf应用程序tomcat启动错误

mpgws1up  于 2021-07-03  发布在  Java
关注(0)|答案(2)|浏览(373)

我正在EclipseMars中使用Tomcat8启动一个SpringHibernateJPaSpringDataMaven jsf应用程序。我在尝试启动服务器时遇到了启动错误,我已经尝试了一个多星期来解决这个问题,我想是时候寻求帮助了!
以下是从控制台打印出来的一些tomcat错误:

...
    08:47:10.900 [localhost-startStop-1] INFO  o.s.b.f.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
  ...
    08:47:10.981 [localhost-startStop-1] ERROR o.s.web.context.ContextLoader - Context initialization failed
    org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 23 in XML document from ServletContext resource [/WEB-INF/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 23; columnNumber: 67; cvc-elt.1: Cannot find the declaration of element 'beans'.
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:399) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    ...
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file
    May 10, 2016 8:47:15 AM org.apache.catalina.core.StandardContext startInternal
    SEVERE: Context [/SilentHomeCemetery_Maven] startup failed due to previous errors
    May 10, 2016 8:47:15 AM org.apache.catalina.core.ApplicationContext log
    INFO: Closing Spring root WebApplicationContext
    08:47:15.465 [localhost-startStop-1] INFO  o.s.w.c.s.XmlWebApplicationContext - Closing Root WebApplicationContext: startup date [Tue May 10 08:47:10 EDT 2016]; root of context hierarchy
    08:47:15.472 [localhost-startStop-1] WARN  o.s.w.c.s.XmlWebApplicationContext - Exception thrown from LifecycleProcessor on context close
    java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: Root WebApplicationContext: startup date [Tue May 10 08:47:10 EDT 2016]; root of context hierarchy
        at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:414) [spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE]

这是我的web.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
      <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
      </listener>
      <listener>
        <listener-class>
            org.springframework.web.context.request.RequestContextListener
        </listener-class>
      </listener>  
      <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/applicationContext.xml           
            </param-value>
      </context-param>
      <context-param>  
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
      </context-param>
      <context-param>
            <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
            <param-value>/WEB-INF/springsecurity.taglib.xml</param-value>
      </context-param> 
      <!-- 
      <filter>
            <filter-name>springSecurityFilterChain</filter-name>
            <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
        </filter>
        <filter-mapping>
            <filter-name>springSecurityFilterChain</filter-name>
            <url-pattern>/*</url-pattern>
      </filter-mapping>
       -->
       <filter>
            <filter-name>loginFilter</filter-name>
            <filter-class>com.kletus.silentHomeCemetery.filters.LoginFilter</filter-class>
       </filter>
       <filter-mapping>
        <filter-name>loginFilter</filter-name>
        <url-pattern>/faces/Admin/*</url-pattern>
       </filter-mapping>
       <filter>
            <filter-name>preventLoginFilter</filter-name>
            <filter-class>com.kletus.silentHomeCemetery.filters.PreventLoginFilter</filter-class>
       </filter>
       <filter-mapping>
        <filter-name>preventLoginFilter</filter-name>
        <url-pattern>/faces/index.xhtml</url-pattern> 
       </filter-mapping>   
      <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>

      <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>  
      <!-- Map these files with JSF -->   
        <url-pattern>/faces/*</url-pattern>
        <url-pattern>*.jsf</url-pattern>
        <url-pattern>*.faces</url-pattern>      
      </servlet-mapping>  

      <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
        <welcome-file>/faces/index.xhtml</welcome-file>    
    </welcome-file-list>

     <context-param>
            <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
            <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
            <param-value>client</param-value>
        </context-param>

      <session-config>
        <session-timeout>30</session-timeout>
      </session-config>
    </web-app>

这是我的applicationcontext.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans
       xmlns="http://www.springframework.org/schema/beans:beans"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"       
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       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/jee 
        http://www.springframework.org/schema/jee/spring-jee.xsd
        http://www.springframework.org/schema/util 
        http://www.springframework.org/schema/util/spring-util.xsd
        http://www.springframework.org/schema/tx
               http://www.springframework.org/schema/tx/spring-tx.xsd       
               http://www.springframework.org/schema/data/jpa 
        http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">

    <!--    http://www.springframework.org/schema/data/jpa/spring-jpa-1.2.xsd"> -->

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven/>

     <!-- Package needed to be scanned for annotation -->
    <context:component-scan base-package="spring"/>

    <!-- Use annotation for configuration-->
    <context:annotation-config/>
    <context:spring-configured/>

    <!-- Handles HTTP GET requests for /resources/**by efficiently serving 
        up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" /> 

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="com.db2.jdbc.Driver" />
        <property name="url" value="jdbc:db2://localhost:50000/SLNTRURO" />
        <property name="username" value="<name>" />
        <property name="password" value="<password>" />
    </bean>    

    <!-- Hibernate 4 SessionFactory Bean definition -->
    <bean id="hibernate4AnnotatedSessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="annotatedClasses">
            <list>
                <value>com.kletus.silentHomeCemetery.model.jpa.GraveInfo</value>
                <value>com.kletus.silentHomeCemetery.model.jpa.Control</value>
                <value>com.kletus.silentHomeCemetery.model.jpa.Encrypted_lot_info</value>
                <value>com.kletus.silentHomeCemetery.model.jpa.EncryptedGraveInfo</value>
                <value>com.kletus.silentHomeCemetery.model.jpa.EncryptionKey</value>
                <value>com.kletus.silentHomeCemetery.model.jpa.LotInfo</value>                
                <value>com.kletus.silentHomeCemetery.model.jpa.Security</value> 
                <value>com.kletus.silentHomeCemetery.model.jpa.SilentHomeUser</value>    
                <value>com.kletus.silentHomeCemetery.model.jpa.UserRole</value> 
                <value>com.kletus.silentHomeCemetery.model.jpa.Role</value>           

            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect
                </prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
    </bean>    

    <bean id="UserDAO" class="com.kletus.silentHomeCemetery.DAO.UserDAO">
        <property name="sessionFactory"
            ref="hibernate4AnnotatedSessionFactory" />
    </bean>

    <context:component-scan base-package="com.kletus.silentHomeCemetery" />

    <bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
    <!-- <property name="defaultPersistenceUnitName" value="nutrition-pu"/> -->
    <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml"/>
    <property name="defaultDataSource" ref="dataSource" />
</bean>

    <!-- JPA -->
    <bean id="entityManager"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="persistenceUnitManager" ref="persistenceUnitManager" />
        <property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
    </bean>

    <!-- jpaVendorAdapter (works in conjunction with the persistence.xml) -->
    <bean id="jpaVendorAdapter"
        class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="database" value="${jpa.database}" />
        <property name="showSql" value="${jpa.showSql}" />
        <property name="databasePlatform" value="${jpa.dialect}" />
        <property name="generateDdl" value="${jpa.generateDdl}" />
        <property name="packagesToScan" value="com.kletus.silentHomeCemetery.model.jpa" />
    </bean>

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

    <bean id="persistenceAnnotation" class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />   

</beans>

这是我的eclipselink-orm.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
    <entity-mappings version="2.5" xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm" 
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
            xsi:schemaLocation="http://www.eclipse.org/eclipselink/xsds/persistence/orm http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_2_5.xsd">
        <named-query name="Control.findAll">
            <query>select c from Control c</query>
        </named-query>
        <named-query name="Encrypted_lot_info.findAll">
            <query>select e from Encrypted_lot_info e</query>
        </named-query>
        <named-query name="EncryptedGraveInfo.findAll">
            <query>select e from EncryptedGraveInfo e</query>
        </named-query>
        <named-query name="EncryptionKey.findAll">
            <query>select e from EncryptionKey e</query>
        </named-query>
        <named-query name="LotInfo.findAll">
            <query>select l from LotInfo l</query>
        </named-query>        
        <named-query name="Security.findAll">
            <query>select s from Security s</query>
        </named-query>

        <named-query name="SilentHomeUser.findAll">
            <query>select u from SilentHomeUser u</query>
        </named-query>

        <named-query name="UserRole.findAll">
            <query>select z from UserRole z</query>
        </named-query>

        <named-query name="Role.findAll">
            <query>select r from Role r</query>
        </named-query>

        <entity class="com.kletus.silentHomeCemetery.model.jpa.Control" access="VIRTUAL">
            <table name="CONTROLS"/>
            <attributes>
                <id name="controlKey" attribute-type="int">
                    <column name="CONTROL_KEY"/>
                    <generated-value strategy="AUTO"/>
                </id>
                <basic name="dateLastBackup" attribute-type="java.util.Date">
                    <column name="DATE_LAST_BACKUP"/>
                    <temporal>DATE</temporal>
                </basic>
                <basic name="dateLastCompact" attribute-type="java.util.Date">
                    <column name="DATE_LAST_COMPACT"/>
                    <temporal>DATE</temporal>
                </basic>
            </attributes>
        </entity>
        <entity class="com.kletus.silentHomeCemetery.model.jpa.Encrypted_lot_info" access="VIRTUAL">
            <table name='"ENCRYPTED LOT INFO"'/>
            <attributes>
                <id name="eLotId" attribute-type="int">
                    <column name="E_LOT_ID"/>
                    <generated-value strategy="AUTO"/>
                </id>
                <basic name="eLot" attribute-type="String">
                    <column name="E_LOT"/>
                </basic>
                <basic name="eLotAddDate" attribute-type="String">
                    <column name="E_LOT_ADD_DATE"/>
                </basic>
                <basic name="eLotChgDate" attribute-type="String">
                    <column name="E_LOT_CHG_DATE"/>
                </basic>
                <basic name="eLotName" attribute-type="String">
                    <column name="E_LOT_NAME"/>
                </basic>
                <basic name="eLotNextOfKin" attribute-type="String">
                    <column name="E_LOT_NEXT_OF_KIN"/>
                </basic>
                <basic name="eLotNotes" attribute-type="String">
                    <column name="E_LOT_NOTES"/>
                </basic>
                <basic name="eLotOrigLotNbr" attribute-type="String">
                    <column name="E_LOT_ORIG_LOT_NBR"/>
                </basic>
                <basic name="eLotUniqId" attribute-type="String">
                    <column name="E_LOT_UNIQ_ID"/>
                </basic>
                <basic name="eUserName" attribute-type="String">
                    <column name="E_USER_NAME"/>
                </basic>
                <basic name="key" attribute-type="String">
                    <column name='"KEY"'/>
                </basic>
            </attributes>
        </entity>
        <entity class="com.kletus.silentHomeCemetery.model.jpa.EncryptedGraveInfo" access="VIRTUAL">
            <table name="ENCRYPTED_GRAVE_INFO"/>
            <attributes>
                <id name="eGraveId" attribute-type="int">
                    <column name="E_GRAVE_ID"/>
                    <generated-value strategy="AUTO"/>
                </id>
                <basic name="dateLastChanged" attribute-type="java.sql.Timestamp">
                    <column name="DATE_LAST_CHANGED"/>
                </basic>
                <basic name="eDeathDate" attribute-type="String">
                    <column name="E_DEATH_DATE"/>
                </basic>
                <basic name="eGraveAddDate" attribute-type="String">
                    <column name="E_GRAVE_ADD_DATE"/>
                </basic>
                <basic name="eGraveChgDate" attribute-type="String">
                    <column name="E_GRAVE_CHG_DATE"/>
                </basic>
                <basic name="eGraveDate" attribute-type="String">
                    <column name="E_GRAVE_DATE"/>
                </basic>
                <basic name="eGraveFuneralDirector" attribute-type="String">
                    <column name="E_GRAVE_FUNERAL_DIRECTOR"/>
                </basic>
                <basic name="eGraveLot" attribute-type="String">
                    <column name="E_GRAVE_LOT"/>
                </basic>
                <basic name="eGraveLotUniqId" attribute-type="String">
                    <column name="E_GRAVE_LOT_UNIQ_ID"/>
                </basic>
                <basic name="eGraveName" attribute-type="String">
                    <column name="E_GRAVE_NAME"/>
                </basic>
                <basic name="eGraveNbr" attribute-type="String">
                    <column name="E_GRAVE_NBR"/>
                </basic>
                <basic name="eGraveNotes" attribute-type="String">
                    <column name="E_GRAVE_NOTES"/>
                </basic>
                <basic name="eUserName" attribute-type="String">
                    <column name="E_USER_NAME"/>
                </basic>
                <basic name="encryptedGraveId" attribute-type="String">
                    <column name="ENCRYPTED_GRAVE_ID"/>
                </basic>
                <basic name="key" attribute-type="String">
                    <column name='"KEY"'/>
                </basic>
            </attributes>
        </entity>
        <entity class="com.kletus.silentHomeCemetery.model.jpa.EncryptionKey" access="VIRTUAL">
            <table name="ENCRYPTION_KEYS"/>
            <attributes>
                <id name="keyTracker" attribute-type="long">
                    <column name="KEY_TRACKER"/>
                    <generated-value strategy="AUTO"/>
                </id>
                <basic name="key" attribute-type="String">
                    <column name='"KEY"'/>
                </basic>
            </attributes>
        </entity>
        <entity class="com.kletus.silentHomeCemetery.model.jpa.LotInfo" access="VIRTUAL">
            <table name="LOT_INFO"/>
            <attributes>
                <id name="lotUniqId" attribute-type="int">
                    <column name="LOT_UNIQ_ID"/>
                    <generated-value strategy="AUTO"/>
                </id>
                <basic name="encryption_key" attribute-type="byte[]">
                    <column name='"ENCRYPTION KEY"'/>
                </basic>
                <basic name="lot" attribute-type="int">
                </basic>
                <basic name="lotAddDate" attribute-type="java.util.Date">
                    <column name="LOT_ADD_DATE"/>
                    <temporal>DATE</temporal>
                </basic>
                <basic name="lotChgDate" attribute-type="java.sql.Timestamp">
                    <column name="LOT_CHG_DATE"/>
                </basic>
                <basic name="lotName" attribute-type="String">
                    <column name="LOT_NAME"/>
                </basic>
                <basic name="lotNextOfKin" attribute-type="String">
                    <column name="LOT_NEXT_OF_KIN"/>
                </basic>
                <basic name="lotNotes" attribute-type="String">
                    <column name="LOT_NOTES"/>
                </basic>
                <basic name="lotOrigLotNbr" attribute-type="String">
                    <column name="LOT_ORIG_LOT_NBR"/>
                </basic>
                <basic name="userName" attribute-type="String">
                    <column name="USER_NAME"/>
                </basic>
            </attributes>
        </entity>
        <entity class="com.kletus.silentHomeCemetery.model.jpa.GraveInfo" access="VIRTUAL">
            <table name="GRAVE_INFO"/>
            <attributes>
                <id name="GraveId" attribute-type="int">
                    <column name="GRAVE_ID"/>
                    <generated-value strategy="AUTO"/>
                </id>
                <basic name="graveChgDate" attribute-type="java.sql.Timestamp">
                    <column name="GRAVE_CHG_DATE"/>
                </basic>
                <basic name="deathDate" attribute-type="java.sql.Timestamp">
                    <column name="DEATH_DATE"/>
                </basic>
                <basic name="graveAddDate" attribute-type="java.sql.Timestamp">
                    <column name="GRAVE_ADD_DATE"/>
                </basic>            
                <basic name="graveDate" attribute-type="String">
                    <column name="GRAVE_DATE"/>
                </basic>
                <basic name="graveFuneralDirector" attribute-type="String">
                    <column name="GRAVE_FUNERAL_DIRECTOR"/>
                </basic>
                <basic name="graveLot" attribute-type="String">
                    <column name="GRAVE_LOT"/>
                </basic>
                <basic name="graveLotUniqId" attribute-type="String">
                    <column name="GRAVE_LOT_UNIQ_ID"/>
                </basic>
                <basic name="graveName" attribute-type="String">
                    <column name="GRAVE_NAME"/>
                </basic>
                <basic name="graveNbr" attribute-type="String">
                    <column name="GRAVE_NBR"/>
                </basic>
                <basic name="graveNotes" attribute-type="String">
                    <column name="GRAVE_NOTES"/>
                </basic>
                <basic name="userName" attribute-type="String">
                    <column name="USER_NAME"/>
                </basic>
                <basic name="encryptKey" attribute-type="Byte">
                    <column name='"ENCRYPT_KEY"'/>
                </basic>
            </attributes>
        </entity>

        <embeddable class='com.kletus.silentHomeCemetery.model.jpa.UserRolePK"' access="VIRTUAL">
            <attributes>
                <basic name="userId" attribute-type="int">
                    <column name="USER_ID"/>
                </basic>
                <basic name="roleId" attribute-type="int">
                    <column name="ROLE_ID"/>
                </basic>
            </attributes>
        </embeddable>

        <entity class='com.kletus.silentHomeCemetery.model.jpa.UserRole"' access="VIRTUAL">
            <table name="USER_ROLES"/>
            <attributes>
                <id name="userId" attribute-type="int">
                    <column name="USER_ID"/>                
                </id>           
                <basic name="roleId" attribute-type="int">
                    <column name="ROLE_ID"/>
                </basic>
            </attributes>
        </entity>

        <entity class='com.kletus.silentHomeCemetery.model.jpa.Role"' access="VIRTUAL">
            <table name="ROLES"/>
            <attributes>
                <id name="roleId" attribute-type="int">
                    <column name="ROLE_ID"/>                
                </id>           
                <basic name="role" attribute-type="String">
                    <column name="ROLE"/>
                </basic>
            </attributes>
        </entity>       

        <entity class='com.kletus.silentHomeCemetery.model.jpa.SilentHomeUser"' access="VIRTUAL">
            <table name="SILENT_HOME_USER"/>
            <attributes>
                <id name="userId" attribute-type="int">
                    <column name="USER_ID"/>                
                </id>           
                <basic name="activeInd" attribute-type="int">
                    <column name="ACTIVE_IND"/>
                </basic>
                <basic name="fName" attribute-type="String">
                    <column name="FNAME"/>
                </basic>
                <basic name="mName" attribute-type="String">
                    <column name="MNAME"/>
                </basic>
                <basic name="lName" attribute-type="String">
                    <column name="LNAME"/>
                </basic>
                <basic name="password" attribute-type="String">
                    <column name="PASSWORD"/>
                </basic>
            </attributes>
        </entity>   

    </entity-mappings>

这是我的spring-config.xml文件:

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

<beans xmlns="http://www.springframework.org/schema/beans:beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context" 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/aop 
          http://www.springframework.org/schema/aop/spring-aop.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:component-scan base-package="com.kletus.SilentHomeCemetery" />

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceXmlLocation" value="classpath:/persistence.xml" />
        <!-- <property name="persistenceUnitName" value="userPersistenceUnit" /> -->
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
        <property name="jpaDialect" ref="jpaDialect" />
    </bean>

    <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="database" value="DB2" />
        <property name="databasePlatform" value="org.hibernate.dialect.DB2Dialect" />
    </bean>

    <bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />

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

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

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver" />    
        <property name="url" value="jdbc:db2://localhost:50000/SLNTRURO:retrieveMessagesFromServerOnGetMessage=true;" />   

        <property name="username" value="<name>" />
        <property name="password" value="<password">"/>
    </bean>
</beans>
wfveoks0

wfveoks01#

架构声明中有错误。

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

应该是

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

这是 applicationContext.xml . 日志清楚地表明了这一点。

lineNumber: 23; columnNumber: 67; cvc-elt.1: Cannot find the declaration of element 'beans'.
7nbnzgx9

7nbnzgx92#

好吧,在我的头撞在墙上几个星期后,我终于得到了工作申请。我仍然不知道为什么这个applicationcontext.xml文件可以工作,因为它看起来不像我见过的任何其他applicationcontext.xml文件,但它确实可以,我不会质疑成功,我只想继续。如果我换成beans:beansxml元素,并将其替换为标准的“beans”格式,我得到各种编译错误,而tomcat8不会启动。如果有人知道为什么这样做,而标准的“beans”元素没有,我很想知道为什么。
非常感谢stack overflow社区的帮助和鼓励,我真的很感激!

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans
   xmlns="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:repository="http://www.springframework.org/schema/data/repository"
xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.0.xsd
    http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.2.xsd
    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/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
    http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository-1.0.xsd">

<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />

 <!-- Package needed to be scanned for annotation -->
<context:component-scan base-package="spring"/>
<context:component-scan base-package="com.base.silentHomeCemetery" />
<context:component-scan base-package="com.base.silentHomeCemetery"/>
<context:component-scan base-package="com.base.silentHomeCemetery.model.jpa"/>
<context:component-scan base-package="com.base.silentHomeCemetery.DAO"/>
<context:component-scan base-package="com.base.silentHomeCemetery.model.repository"/>
<context:component-scan
base-package="com.base.silentHomeCemetery.model.repository.Impl"/>
<context:component-scan base-package="com.base.silentHomeCemetery.service"/>
<context:component-scan base-package="com.base.silentHomeCemetery.service.Impl"/>

<!-- Use annotation for configuration-->
<context:annotation-config/>
<context:spring-configured/>

<!-- Handles HTTP GET requests for /resources/**by efficiently serving 
    up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />      

<beans:bean id="userDAO" class="com.base.silentHomeCemetery.DAO.UserDAO">  
    <beans:property name="userDAO" ref="userDAO"/>
    <beans:property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>   

<beans:bean id="dataSource"
            class="org.springframework.jdbc.datasource.DriverManagerDataSource" >       
    <beans:property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver"/>
    <beans:property name="url"
        value="jdbc:db2://localhost:50000/SLNTRURO" />
    <beans:property name="username" value="name" />
    <beans:property name="password" value="password" />
</beans:bean>

<!-- Hibernate 4 SessionFactory Bean definition -->
<beans:bean id="hibernate4AnnotatedSessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <beans:property name="dataSource" ref="dataSource" />
    <beans:property name="annotatedClasses">
        <beans:list>
            <beans:value>com.base.silentHomeCemetery.model.jpa.GraveInfo</beans:value>
            <beans:value>com.base.silentHomeCemetery.model.jpa.Control</beans:value>
            <beans:value>com.base.silentHomeCemetery.model.jpa.Encrypted_lot_info</beans:value>
            <beans:value>com.base.silentHomeCemetery.model.jpa.EncryptedGraveInfo</beans:value>
            <beans:value>com.base.silentHomeCemetery.model.jpa.EncryptionKey</beans:value>
            <beans:value>com.base.silentHomeCemetery.model.jpa.LotInfo</beans:value>                
            <beans:value>com.base.silentHomeCemetery.model.jpa.Security</beans:value> 
            <beans:value>com.base.silentHomeCemetery.model.jpa.SilentHomeUser</beans:value>    
            <beans:value>com.base.silentHomeCemetery.model.jpa.UserRole</beans:value> 
            <beans:value>com.base.silentHomeCemetery.model.jpa.Role</beans:value>           

        </beans:list>
    </beans:property>
    <beans:property name="hibernateProperties">
        <beans:props>
            <beans:prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect
            </beans:prop>
            <beans:prop key="hibernate.show_sql">true</beans:prop>
        </beans:props>
    </beans:property>
</beans:bean>

<beans:bean id="entityManagerFactory" p:dataSource-ref="dataSource"
 class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <beans:property name="persistenceXmlLocation" value="classpath:/META-INF/eclipselink-
<orm.xml" />
    <beans:property name="packagesToScan" value="com.base.silentHomeCemetery" />
    <beans:property name="dataSource" ref="dataSource" />

    <beans:property name="jpaProperties">
        <beans:props>
            <beans:prop key="hibernate.show_sql">true</beans:prop>
            <beans:prop key="hibernate.hbm2ddl.auto">create</beans:prop>
            <beans:prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect</beans:prop>
        </beans:props>
    </beans:property>

    <beans:property name="persistenceProvider">
        <beans:bean class="org.hibernate.jpa.HibernatePersistenceProvider"/>
    </beans:property>
</beans:bean>

<beans:bean id="log4jInitialization"
 class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">  
    <beans:property name="targetClass" value="org.springframework.util.Log4jConfigurer"/>
    <beans:property name="targetMethod" value="initLogging"/>
    <beans:property name="arguments">
        <beans:list>
            <beans:value>log4j.properties</beans:value>
            <beans:value>WEB-INF/classes/log4j.xml</beans:value>classpath:/config/log4j-    silentHomeCemetery.xml NO classpath:/log4j.xml NO
        </beans:list>
    </beans:property>   
</beans:bean>   

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

<beans:bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <beans:property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>

相关问题