Spring web mvc javax / servlet / Servlet

时间:2015-11-13 13:24:24

标签: spring

我面临一个错误 enter image description here 请问某人有问题吗? 这是我的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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.ncorp.banque</groupId>
<artifactId>enspWebSite</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>enspWebSite</name>

<properties>
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <java-version>1.8</java-version> 
    <org.springframework-version>
        pom.xml
        4.2.2.RELEASE </org.springframework-version> 
    <org.aspectj-version>1.6.10</org.aspectj-version> 
    <org.slf4j-version>1.6.6</org.slf4j-version> 

</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>4.2.2.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet.jsp.jstl</groupId>
        <artifactId>javax.servlet.jsp.jstl-api</artifactId>
        <version>1.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>javax.servlet.jsp.jstl</artifactId>
        <version>1.2.2</version>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>
    <!--@Inject--> 
    <dependency> 
        <groupId>javax.inject</groupId> 
        <artifactId>javax.inject</artifactId> 
        <version>1</version> 
    </dependency> <!--AspectJ--> 
    <dependency> 
        <groupId>org.aspectj</groupId> 
        <artifactId>aspectjrt</artifactId> 
        <version> ${org.aspectj-version} </version> 
    </dependency> 
    <!--Spring--> 
    <dependency> 
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.2.1.RELEASE</version>
        <exclusions>
            <!--Exclude Commons Logging in favor of SLF4j --> 
            <exclusion> 
                <groupId>commons-logging</groupId> 
                <artifactId>commons-logging</artifactId> 
            </exclusion> 
        </exclusions> 
    </dependency>
    <!--Spring--> 
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.2.1.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>4.2.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.0.2.Final</version>


    </dependency>


    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>4.2.1.RELEASE</version>
    </dependency> 
    <!--HibernteJPA --> 
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.0.2.Final</version>

    </dependency>
    <!--HibernteJPA -->

    <dependency> 
        <groupId>org.hibernate</groupId> 
        <artifactId>hibernate-validator</artifactId> 
        <version>4.1.0.Final</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>
    <!--Servlet--> 
    <dependency> 
        <groupId>javax.servlet</groupId> 
        <artifactId>servlet-api</artifactId> 
        <version>3.0-alpha-1</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> 
    </dependency>
    <!--Test -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.7</version>
        <scope>test</scope>
    </dependency>
    <!--MySQL JDBC Driver -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId> 
        <version>5.1.6</version>
    </dependency>
    <!--To generateJSON withjackson-->
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-core-asl</artifactId>
        <version>1.9.10</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.9.10</version>
    </dependency>
    <!--SpringSecurity --> 
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>4.0.2.RELEASE</version>
    </dependency>

    <dependency> 
        <groupId>org.springframework.security</groupId> 
        <artifactId>spring-security-config</artifactId> 
        <version>3.2.0.RELEASE</version> 
    </dependency> 
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>4.0.2.RELEASE</version>
    </dependency>



</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <compilerArguments>
                    <endorseddirs>${endorsed.dir}</endorseddirs>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${endorsed.dir}</outputDirectory>
                        <silent>true</silent>
                        <artifactItems>
                            <artifactItem>
                                <groupId>javax</groupId>
                                <artifactId>javaee-endorsed-api</artifactId>
                                <version>7.0</version>
                                <type>jar</type>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<!--repositories>
    <repository>
        <id>unknown-jars-temp-repo</id>
        <name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name>
        <url>file:${project.basedir}/lib</url>
    </repository>
</repositories-->

我不知道这是我的罐子里的问题还是什么。

2 个答案:

答案 0 :(得分:0)

为什么使用3.0-alpha-1? 试试这个:

<dependency>
<groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>6.0</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
</dependency>

答案 1 :(得分:0)

我终于解决了这个问题。事实上,servlet-api版本存在问题。我使用的是Spring配置类而不是xml配置,因此它适用于Servlet 3.0 +,但提供了依赖关系中的范围,这意味着系统在编译时(可能是tomcat)解决了依赖关系。我只是更改依赖项并删除提供的范围。

 <!--Servlet--> 
        <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>4.0.0-b01</version>
        </dependency>

另一个解决方案可以使用spring-boot