java.lang.NoClassDefFoundError: javax/el/PropertyNotFoundException 当我向控制器发送无效值时

Posted

技术标签:

【中文标题】java.lang.NoClassDefFoundError: javax/el/PropertyNotFoundException 当我向控制器发送无效值时【英文标题】:java.lang.NoClassDefFoundError: javax/el/PropertyNotFoundException when I send invalid values to controller 【发布时间】:2013-10-27 10:10:59 【问题描述】:

我使用 MockMvc 进行控制器测试

@Test
    public void updateEvent() throws Exception
        MockHttpServletRequestBuilder request = MockMvcRequestBuilders
                .post("/updateEvent");
        request.param("selectedEventStatusId", "1");
        request.param("selectedEventTypeId", "1");



        Event eventFromDb = createAndSaveEvent();
        request.param("idEvent", eventFromDb.getId().toString());
        request.param("name", eventFromDb.getName());
        request.param("description", eventFromDb.getDescription() +"____");//the reason of problem. if I will write request.param("description", eventFromDb.getDescription() );  its good work mapping if this field below
        request.param("date", new SimpleDateFormat("yyyy-MM-dd").format(eventFromDb.getDate()));
        request.param("eventDate", new SimpleDateFormat("yyyy-MM-dd").format(eventFromDb.getEventDate()));


        ResultActions result = mockMvc.perform(request).andDo(MockMvcResultHandlers.print());

        result.andExpect(MockMvcResultMatchers.view().name("redirect:eventDetails"));
        result.andExpect(MockMvcResultMatchers.model().attributeExists("idEvent"));
        result.andExpect(MockMvcResultMatchers.model().attributeExists("message"));

    

描述字段标记为

    @Size(min=5)
    @Pattern(regexp="[a-zA-Z]*")    
    private String description;

执行后我看到下一个 stackTrace:

 org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: javax/el/PropertyNotFoundException
        at org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1259)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
        at ....

在生产模式下它工作得很好,但在测试中如果我没有有效值,我会看到错误

控制器方法:

@RequestMapping(value = "/updateEvent", method = RequestMethod.POST)
    public String updateEvent(Model model,
            @Valid @ModelAttribute("existedEvent") Event event,
            BindingResult result,
            @ModelAttribute("linkedCandidates") Set<Candidate> candidates,
            @ModelAttribute("linkedvacancies") Set<Vacancy> vacancies,
            @RequestParam(required = true, value = "selectedEventStatusId")Integer EventStatusId,
            @RequestParam(required = true, value = "selectedEventTypeId")Integer EventTypeId ,
            RedirectAttributes attributes) 
        if (result.hasErrors()) 
            //model.addAttribute("idEvent", event.getId());
            event.setCandidates(candidates);
            event.setVacancies(vacancies);
            return "eventDetails";
        
        eventService.updateEventAndLinkedEntities(event, candidates, vacancies,EventTypeId,EventStatusId);
        attributes.addAttribute("idEvent",event.getId() );
        attributes.addAttribute("message", "submitted correctly at "+new Date());
        return "redirect:eventDetails";
    

如果我替换

 request.param("description", eventFromDb.getDescription() +"____"); 

request.param("description", eventFromDb.getDescription();//valid value here

这是好作品

你能帮忙解决吗?

更新

pom.xml(子模块 - 在这里运行的测试)

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.epam.hhs</groupId>
    <artifactId>ui</artifactId>
    <name>hhsystem ui</name>
    <packaging>war</packaging>
    <version>1.0.0-SNAPSHOT</version>
    <properties>
        <java-version>1.6</java-version>
        <org.springframework-version>3.2.3.RELEASE</org.springframework-version>
        <org.springsecurity-version>3.1.3.RELEASE</org.springsecurity-version>
        <org.aspectj-version>1.6.10</org.aspectj-version>
        <org.slf4j-version>1.6.6</org.slf4j-version>
        <!-- Spring -->
        <spring-framework.version>3.2.3.RELEASE</spring-framework.version>
    </properties>
    <dependencies>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>$org.springframework-version</version>
            <exclusions>
                <!-- Exclude Commons Logging in favor of SLF4j -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>$org.springframework-version</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>$org.springframework-version</version>
        </dependency>

        <!-- Spring Security -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>$org.springsecurity-version</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>$org.springsecurity-version</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>$org.springsecurity-version</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>
            <version>$org.springsecurity-version</version>
            <exclusions>
                <exclusion>
                    <artifactId>spring-aop</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Validation -->
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.1.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.0.1.Final</version>
        </dependency>

        <!-- Core -->
        <dependency>
            <groupId>com.epam.hhs</groupId>
            <artifactId>core</artifactId>
            <version>1.0.9-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.epam.hhs</groupId>
            <artifactId>core</artifactId>
            <version>1.0.9-SNAPSHOT</version>
            <classifier>tests</classifier>
        </dependency>

        <!-- AspectJ -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>$org.aspectj-version</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.15</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.mail</groupId>
                    <artifactId>mail</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.jms</groupId>
                    <artifactId>jms</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
            </exclusions>
            <scope>runtime</scope>
        </dependency>

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

        <!-- Servlet -->
         <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope> 
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
            <scope>provided</scope> 
        </dependency> 
        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>el-api</artifactId>
            <version>2.2</version>
            <scope>provided</scope> 
        </dependency>


        <!-- Test -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.7</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.9.5</version>
        </dependency>
        <!-- Mock MVC Test -->
        <!-- <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test-mvc</artifactId> 
            <version>1.0.0.M2</version> <scope>test</scope> </dependency> -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>$spring-framework.version</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <version>1.3</version>
            <scope>test</scope>
        </dependency>
        <!-- <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> 
            <version>4.10</version> <scope>test</scope> <exclusions> <exclusion> <artifactId>hamcrest-core</artifactId> 
            <groupId>org.hamcrest</groupId> </exclusion> </exclusions> </dependency> -->
        <!-- <dependency> <groupId>com.github.springtestdbunit</groupId> <artifactId>spring-test-dbunit</artifactId> 
            <version>1.0.0</version> <scope>test</scope> </dependency> <dependency> <groupId>org.dbunit</groupId> 
            <artifactId>dbunit</artifactId> <version>2.4.8</version> <scope>test</scope> 
            </dependency> -->

    </dependencies>

    <repositories>
        <repository>
            <id>spring-milestone</id>
            <name>Spring Portfolio Milestone Repository</name>
            <url>http://repo.springsource.org/milestone/</url>
        </repository>
    </repositories>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <additionalProjectnatures>
                        <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                    </additionalProjectnatures>
                    <additionalBuildcommands>
                        <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                    </additionalBuildcommands>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArgument>-Xlint:all</compilerArgument>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <configuration>
                    <mainClass>org.test.int1.Main</mainClass>
                </configuration>
            </plugin>
            <!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> 
                <version>2.12</version> <configuration> <forkMode>always</forkMode> </configuration> 
                </plugin> -->
        </plugins>
    </build>
</project>

pom.xml(父模块)

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.epam.hhs</groupId>
    <artifactId>core</artifactId>
    <version>1.0.9-SNAPSHOT</version>

    <name>hhsystem core</name>
    <!--<packaging>war</packaging> -->

    <properties>

        <!-- Generic properties -->
        <java.version>1.6</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <!-- Spring -->
        <spring-framework.version>3.2.3.RELEASE</spring-framework.version>
        <spring-data-jpa.version>1.3.2.RELEASE</spring-data-jpa.version>
        <org.springsecurity-version>3.1.3.RELEASE</org.springsecurity-version>

        <!-- Java EE / Java SE dependencies -->
        <jsp.version>2.2</jsp.version>
        <jstl.version>1.2</jstl.version>
        <servlet.version>2.5</servlet.version>
        <jaxb-impl.version>2.2.7</jaxb-impl.version>

        <!-- Hibernate / JPA -->
        <hibernate.version>4.2.1.Final</hibernate.version>

        <!-- Bean validation -->
        <hibernate-validator.version>4.3.1.Final</hibernate-validator.version>

        <!-- Database access -->
        <tomcat-jdbc.version>7.0.37</tomcat-jdbc.version>
        <ehcache.version>2.6.6</ehcache.version>
        <hsqldb.version>2.2.9</hsqldb.version>

        <!-- AOP -->
        <aspectj.version>1.7.2</aspectj.version>

        <!-- Logging -->
        <logback.version>1.0.13</logback.version>
        <slf4j.version>1.7.5</slf4j.version>

        <!-- RSS -->
        <rome.version>1.0</rome.version>

        <!-- Test -->
        <junit.version>4.11</junit.version>
        <hamcrest.version>1.3</hamcrest.version>

        <!-- Dates -->
        <jodatime-hibernate.version>1.3</jodatime-hibernate.version>
        <jodatime-jsptags.version>1.1.1</jodatime-jsptags.version>
        <jodatime.version>2.2</jodatime.version>
        <jadira-usertype-core.version>3.1.0.CR6</jadira-usertype-core.version>


        <!-- Web dependencies -->
        <webjars-bootstrap.version>2.3.0</webjars-bootstrap.version>
        <webjars-jquery-ui.version>1.9.2</webjars-jquery-ui.version>
        <webjars-jquery.version>1.9.0</webjars-jquery.version>
        <dandelion.datatables.version>0.8.14</dandelion.datatables.version>

        <mysql.version>5.1.22</mysql.version>

    </properties>

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

        <dependency>
            <groupId>org.mule.transports</groupId>
            <artifactId>mule-transport-http</artifactId>
            <version>3.4.0</version>
        </dependency>


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

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>3.2.1.RELEASE</version>
        </dependency>

        <!-- <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>$jstl.version</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>$servlet.version</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>$jsp.version</version>
            <scope>provided</scope>
        </dependency> -->
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>$jaxb-impl.version</version>
            <scope>provided</scope>
        </dependency>
        <!-- SPRING, SPRING, SPRINGITY SPRING -->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>$spring-data-jpa.version</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>$spring-framework.version</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>$spring-framework.version</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>$spring-framework.version</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>$spring-framework.version</version>
        </dependency>
        <!-- used for EhCacheCacheManager -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>$spring-framework.version</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>$spring-framework.version</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-oxm</artifactId>
            <version>$spring-framework.version</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-lang</groupId>
                    <artifactId>commons-lang</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jms</artifactId>
            <version>$spring-framework.version</version>
        </dependency>


        <!-- Database connection pool See here for more details on commons-dbcp 
            versus tomcat-jdbc: http://blog.ippon.fr/2013/03/13/improving-the-performance-of-the-spring-petclinic-sample-application-part-3-of-5/ -->
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-jdbc</artifactId>
            <version>$tomcat-jdbc.version</version>
            <scope>runtime</scope>
        </dependency>

        <!-- For MySql only -->
        <!-- <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> 
            <version>$mysql.version</version> </dependency> -->
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>sqljdbc4</artifactId>
            <version>3.0</version>
        </dependency>
        <!-- <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> 
            <version>$mysql.version</version> </dependency> -->
        <!-- HIBERNATE -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>$hibernate.version</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>$hibernate.version</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>$hibernate-validator.version</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-ehcache</artifactId>
            <version>$hibernate.version</version>
        </dependency>

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

        <!-- Webjars (static dependencies distributed as JAR files) -->
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>$webjars-bootstrap.version</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery-ui</artifactId>
            <version>$webjars-jquery-ui.version</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>$webjars-jquery.version</version>
        </dependency>

        <!-- Test Artifacts -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>$spring-framework.version</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>$junit.version</version>
            <scope>test</scope>
        </dependency>
        <!-- used by Spring MVC Test framework -->
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-library</artifactId>
            <version>$hamcrest.version</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>$aspectj.version</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>$aspectj.version</version>
            <scope>runtime</scope>
        </dependency>

        <!-- Spring Security -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>$org.springsecurity-version</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>$org.springsecurity-version</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>$org.springsecurity-version</version>
        </dependency>
        <dependency>
            <groupId>org.ow2.easybeans</groupId>
            <artifactId>easybeans-uberjar-eclipselink</artifactId>
            <version>1.2.0-M1</version>
        </dependency>
    </dependencies>

    <!-- Maven plugin versions are mentioned in order to guarantee the build 
        reproducibility in the long term -->
    <build>
        <defaultGoal>install</defaultGoal>
        <testResources>
            <testResource>
                <!-- declared explicitly so Spring config files can be placed next to 
                    their corresponding JUnit test class (see example with ValidatorTests) -->
                <directory>$project.basedir/src/test/java</directory>
            </testResource>
            <testResource>
                <directory>$project.basedir/src/test/resources</directory>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <compilerArguments>
                        <Xlint />
                    </compilerArguments>
                    <verbose>true</verbose>
                    <source>$java.version</source>
                    <target>$java.version</target>
                    <showWarnings>true</showWarnings>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                    <wtpversion>2.0</wtpversion>
                    <sourceIncludes>
                        <sourceInclude>**/*.*</sourceInclude>
                    </sourceIncludes>
                    <additionalBuildcommands>
                        <buildCommand>
                            <name>org.springframework.ide.eclipse.core.springbuilder</name>
                        </buildCommand>
                        <buildCommand>
                            <name>org.eclipse.m2e.core.maven2Builder</name>
                        </buildCommand>
                    </additionalBuildcommands>
                    <additionalProjectnatures>
                        <projectnature>org.eclipse.jdt.core.javanature</projectnature>
                        <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                        <projectnature>org.eclipse.m2e.core.maven2Nature</projectnature>
                    </additionalProjectnatures>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.0</version>
                <configuration>
                    <server>tomcat-development-server</server>
                    <port>9966</port>
                    <path>/petclinic</path>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>test-jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

我重新启动我的电脑,现在我看到了其他错误(也许我改变了一些东西但我发布了 pom.xml 的实际 dtate)

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoSuchMethodError: javax.el.ExpressionFactory.newInstance()Ljavax/el/ExpressionFactory;
    at org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1259)
    at ...

如果我在 2.2 上更改 jsp-api 版本

我看到下一条踪迹:

    updateEvent(com.epam.hhsystem.web.controllers.EventMenuControllerTest)  Time elapsed: 0.398 sec  <<< ERROR!
    org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.ExceptionInInitializerError
        at org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1259)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
....
Caused by: java.lang.ExceptionInInitializerError
    at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.interpolateExpression(ResourceBundleMessageInterpolator.java:227)

    ....
Caused by: javax.el.ELException: Provider com.sun.el.ExpressionFactoryImpl not found
    at javax.el.FactoryFinder.newInstance(FactoryFinder.java:97)

...
Caused by: java.lang.ClassNotFoundException: com.sun.el.ExpressionFactoryImpl
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)

【问题讨论】:

【参考方案1】:

我遇到了同样的问题,添加以下依赖解决了这个问题。

当你遇到javax/el/PropertyNotFoundException,那意味着你错过了el-api依赖,你可以添加如下jar

    <dependency>
        <groupId>javax.el</groupId>
        <artifactId>el-api</artifactId>
        <version>2.2</version>
        <scope>provided</scope>
    </dependency>

<dependency>
  <groupId>javax.el</groupId>
  <artifactId>javax.el-api</artifactId>
  <version>3.0.0</version>
  <scope>test</scope>
</dependency>

然后你遇到了 ClassNotFoundException:com.sun.el.E​​xpressionFactoryImpl ,你错过了 el-impl jar:

<dependency>
  <groupId>org.glassfish.web</groupId>
  <artifactId>el-impl</artifactId>
  <version>2.2</version>
  <scope>test</scope>
</dependency>

【讨论】:

我和发布问题的人有同样的问题,这个答案对我有用! Place 认为这是正确的。 @AlperAkture 的回答也一样 如果你添加el-impl,那么你可以从pom中移除el-api的依赖。它将被 el-impl 包含为传递依赖项。 如果在测试范围内添加el-impl,那么在正常的compile 阶段它不会自动可用。【参考方案2】:

将以下内容添加到您的 pom.xml 中。

<dependency>
  <groupId>org.glassfish.web</groupId>
  <artifactId>el-impl</artifactId>
  <version>2.2.6</version>
  <scope>test</scope>
</dependency>

它将解决对 javax.el 的需求。当前版本是 2.2.6

【讨论】:

2.2.6 版真的在 maven repo 中可用吗?我没有找到它here。我的问题在 2.2 版本中得到解决。 有关为什么需要添加它的一些背景信息,请参阅Hibernate Validator Get Started Guide。它还显示哪个版本应该与最新的休眠版本一起使用。【参考方案3】:

我的 pom.xml 中没有 el-impl

 <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>2.5</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.servlet.jsp</groupId>
                <artifactId>jsp-api</artifactId>
                <version>2.2</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>jstl</artifactId>
                <version>1.2</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.el</groupId>
                <artifactId>el-api</artifactId>
                <version>2.2</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>org.glassfish.web</groupId>
                <artifactId>el-impl</artifactId>
                <version>2.2</version>
            </dependency>

是 pom.xml 的工作状态

我又删了一个

servlet-api
jsp-api
jstl
el-api

来自tomcat/lib的jar文件

并从m2./repository复制。

【讨论】:

【参考方案4】:

您可能只需要在测试中添加依赖项。你用的是maven吗?如果是这样,您可以尝试将其添加到您的 pom 中吗?你可能需要一个不同的 jar/版本,但是像这样:

<dependency>
  <groupId>javax.el</groupId>
  <artifactId>javax.el-api</artifactId>
  <version>3.0.0</version>
  <scope>test</scope>
</dependency>

【讨论】:

你是对的。我使用 Maven。我的项目包含 2 个模块。此测试在子模块中。我有类似的依赖。 with ** javax.elel-apiprovided2.2 **跨度> 您确定 test 和 prod 中的版本相同吗?您是如何从命令行或使用 IDE 运行测试的? 哦,你有 provided,你可以尝试删除它或使其成为 test 吗?我不确定是否包含提供的范围依赖项来运行测试。此外,您可能想要验证缺少的类是否在 jar 中,您可以执行类似“jar -tvf el-api-3.0.0.jar | grep PropertyNotFoundException”的操作 似乎 provided 将包含在测试中,所以这不是问题。我还看到 PropertyNotFoundException.class 在 2.2 jar 中。所以问题一定出在pom设置中。你想把这些贴在这里吗? 我看到 jsp-api-2.1 有一个抽象的 javax.el.E​​xpressionFactory 但没有 newInstance() 方法,正如你所发现的。 jsp-api-2.2 删除了 ExpressionFactory,所以它从 el-api-2.2 中提取它,但是没有实现(我可以在你的 pom 中看到)。我确实在这个依赖项中找到了一个 ExpressionFactoryImpl: com.sun.elel-ri1.0 ,这可能会修复你最新的ClassNotFoundException,你可以试试,可能会导致另一个错误。我也会看看更多的东西来尝试。

以上是关于java.lang.NoClassDefFoundError: javax/el/PropertyNotFoundException 当我向控制器发送无效值时的主要内容,如果未能解决你的问题,请参考以下文章