上下文初始化时出现spring和jpa错误

时间:2011-05-09 05:14:04

标签: java hibernate spring jsf jpa

我有这种错误,也许你可以知道原因:(

我之前尝试更改Spring和hibernate / jpa的版本,但它没有解决问题....

    INFO: ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
java.lang.NoSuchMethodError: org.springframework.util.Assert.noNullElements([Ljava/lang/Object;Ljava/lang/String;)V
    at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.setConfigLocations(AbstractRefreshableConfigApplicationContext.java:78)
    at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.setConfigLocation(AbstractRefreshableConfigApplicationContext.java:69)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:253)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4623)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5323)
    at com.sun.enterprise.web.WebModule.start(WebModule.java:456)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:922)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:906)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:696)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2205)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1890)
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:85)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.start(ApplicationLifecycle.java:560)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.start(ApplicationLifecycle.java:547)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:189)
    at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:329)
    at com.sun.enterprise.v3.admin.CommandRunner$2.execute(CommandRunner.java:302)
    at com.sun.enterprise.v3.admin.CommandRunner.doCommand(CommandRunner.java:312)
    at com.sun.enterprise.v3.admin.CommandRunner.doCommand(CommandRunner.java:119)
    at com.sun.enterprise.v3.admin.CommandRunner.doCommand(CommandRunner.java:99)
    at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:250)
    at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:176)
    at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:147)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:180)
    at com.sun.grizzly.http.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:633)
    at com.sun.grizzly.http.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:570)
    at com.sun.grizzly.http.DefaultProcessorTask.process(DefaultProcessorTask.java:827)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:152)
    at com.sun.enterprise.v3.services.impl.GlassfishProtocolChain.executeProtocolFilter(GlassfishProtocolChain.java:71)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:103)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:89)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:67)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:56)
    at com.sun.grizzly.util.WorkerThreadImpl.processTask(WorkerThreadImpl.java:325)
    at com.sun.grizzly.util.WorkerThreadImpl.run(WorkerThreadImpl.java:184)

GRAVE: WebModule[/book]PWC1275: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NoSuchMethodError: org.springframework.util.Assert.noNullElements([Ljava/lang/Object;Ljava/lang/String;)V
    at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.setConfigLocations(AbstractRefreshableConfigApplicationContext.java:78)
    at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.setConfigLocation(AbstractRefreshableConfigApplicationContext.java:69)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:253)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4623)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5323)
    at com.sun.enterprise.web.WebModule.start(WebModule.java:456)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:922)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:906)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:696)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2205)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1890)
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:85)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.start(ApplicationLifecycle.java:560)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.start(ApplicationLifecycle.java:547)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:189)
    at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:329)
    at com.sun.enterprise.v3.admin.CommandRunner$2.execute(CommandRunner.java:302)
    at com.sun.enterprise.v3.admin.CommandRunner.doCommand(CommandRunner.java:312)
    at com.sun.enterprise.v3.admin.CommandRunner.doCommand(CommandRunner.java:119)
    at com.sun.enterprise.v3.admin.CommandRunner.doCommand(CommandRunner.java:99)
    at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:250)
    at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:176)
    at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:147)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:180)
    at com.sun.grizzly.http.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:633)
    at com.sun.grizzly.http.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:570)
    at com.sun.grizzly.http.DefaultProcessorTask.process(DefaultProcessorTask.java:827)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:152)
    at com.sun.enterprise.v3.services.impl.GlassfishProtocolChain.executeProtocolFilter(GlassfishProtocolChain.java:71)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:103)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:89)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:67)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:56)
    at com.sun.grizzly.util.WorkerThreadImpl.processTask(WorkerThreadImpl.java:325)
    at com.sun.grizzly.util.WorkerThreadImpl.run(WorkerThreadImpl.java:184)

所以,我有这个web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Use this definition if using a Java EE 6 container This also stops Eclipse 
    from complaining that 3.0 is not a valid version <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" 
    http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> -->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">

    <!-- The definition of the Root Spring Container shared by all Servlets 
        and Filters -->

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/spring/root-context.xml
        </param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/app/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/spring/</url-pattern>
    </servlet-mapping>

    <context-param>
        <param-name>facelets.DEVELOPMENT</param-name>
        <param-value>true</param-value>
    </context-param>
    <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>*.jsf</url-pattern>
    </servlet-mapping>

</web-app>

和这个context.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:mvc="http://www.springframework.org/schema/mvc"
    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-3.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd  
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd" default-autowire="byName">

<context:component-scan base-package="com.mytel.project.book" />

    <!-- Scans within the base package of the application for @Components to configure as beans -->
    <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:db.properties" />
    </bean>

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

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="database" value="POSTGRESQL" />
                <property name="showSql" value="true" />
                <property name="generateDdl" value="false" />
                <property name="databasePlatform" value="${db.dialect}" />
            </bean>
        </property>     
    </bean>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="${db.driver}" />
        <property name="url" value="${db.url}" />
        <property name="username" value="${db.username}" />
        <property name="password" value="${db.password}" />
    </bean>

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

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

</beans>

我的版本是:

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <jetty.version>6.1.4</jetty.version>
        <spring.version>3.0.5.RELEASE</spring.version>
        <slf4j.version>1.5.10</slf4j.version>
        <java.version>1.5</java.version>
        <junit.version>4.8.2</junit.version>
    </properties>

        <dependency>
            <groupId>javax.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>javax.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>1.2-b19</version>
        </dependency>

        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.0.0.GA</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>4.0.0.GA</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>3.6.0.Final</version>
        </dependency>


        <!-- Spring Dependencies -->

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

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

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

谢谢你的帮助!

1 个答案:

答案 0 :(得分:2)

你的类路径中有两个版本或一个坏版本的Spring Core:清理你的glassfish / tomcat commons lib文件夹(在eclipse中,清理服务器上的工作目录)并清理你的Maven项目依赖项(mvn clean eclipse:clean eclipse) :eclipse + refresh)。