Spring mvc annotation配置。升级到弹簧4.3.9时出错404

时间:2017-08-15 18:37:29

标签: java spring maven spring-mvc tomcat

我的java spring mvc项目位于4.0.6.RELEASE spring version Project在http://localhost:8080/加载主页。当我在pom.xml中更改为更新的4.3.9.RELEASE时,我收到错误404 tomcat page。

我使用tomcat Apache Tomcat / 9.0.0.M22,IntelliJ,windows10,chrome(但边缘也显示404)。我试图重建项目,刷新maven,但它没有用。

我已经附加了配置文件和文件夹结构。我希望它不是太多的代码。感谢您的帮助。

的AppConfig

$elasticsearch.search type: 'application_development_tags', type: 'tag

AppController的

/** imports */

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.websystique.springmvc")
public class AppConfig {

@Bean
public ViewResolver viewResolver() {
    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setViewClass(JstlView.class);
    viewResolver.setPrefix("/WEB-INF/views/");
    viewResolver.setSuffix(".jsp");
    return viewResolver;
}

@Bean
public MessageSource messageSource() {
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename("messages");
    return messageSource;
}
}

的pom.xml

/** imports */
@Controller
@RequestMapping("/")
public class AppController {

@Autowired
QuestionService service;

@Autowired
MessageSource messageSource;

@Autowired
PointsCounter pointsCounter;

private List<Answer> answerList;

/**
 * Load home page
 */
@RequestMapping(value = "/")
public String mainPage(ModelMap modelMap) {
    return "home";
}

/** More methods (...)

My folder structure

编辑--------- 我的服务器日志(IntelliJ) - Spring 4.3.9 - 错误404

<?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>websystique</groupId>
<artifactId>websystique</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <springframework.version>4.3.9.RELEASE</springframework.version>
    <hibernate.version>4.3.6.Final</hibernate.version>
    <mysql.connector.version>5.1.31</mysql.connector.version>
    <joda-time.version>2.3</joda-time.version>
    <testng.version>6.9.4</testng.version>
    <mockito.version>1.10.19</mockito.version>
    <h2.version>1.4.187</h2.version>
    <dbunit.version>2.2</dbunit.version>
</properties>

<dependencies>
    <!-- Spring -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${springframework.version}</version>
    </dependency>

    <!-- Hibernate -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>${hibernate.version}</version>
    </dependency>

    <!-- jsr303 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.1.3.Final</version>
    </dependency>

    <!-- MySQL -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>${mysql.connector.version}</version>
    </dependency>

    <!-- Joda-Time -->
    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>${joda-time.version}</version>
    </dependency>

    <!-- To map JodaTime with database type -->
    <dependency>
        <groupId>org.jadira.usertype</groupId>
        <artifactId>usertype.core</artifactId>
        <version>3.0.0.CR1</version>
    </dependency>

    <!-- Servlet+JSP+JSTL -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>javax.servlet.jsp-api</artifactId>
        <version>2.3.1</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>


    <!-- Testing dependencies -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${springframework.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>${testng.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>${mockito.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>${h2.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>dbunit</groupId>
        <artifactId>dbunit</artifactId>
        <version>${dbunit.version}</version>
        <scope>test</scope>
    </dependency>

</dependencies>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <warSourceDirectory>src/main/webapp</warSourceDirectory>
                    <warName>SpringHibernateExample</warName>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
    <finalName>SpringHibernateExample</finalName>
</build>

Chrome显示了这一点:

"C:\Program Files\Apache Software Foundation\Tomcat 9.0\bin\catalina.bat" 
run
[2017-08-16 01:30:24,219] Artifact questions-websystique:war exploded: 
Waiting for server connection to start artifact deployment...
Using CATALINA_BASE:   "C:\Users\Max\.IntelliJIdea2017.2\system\tomcat\Unnamed_websystique_20"
Using CATALINA_HOME:   "C:\Program Files\Apache Software Foundation\Tomcat 9.0"
Using CATALINA_TMPDIR: "C:\Program Files\Apache Software Foundation\Tomcat 9.0\temp"
Using JRE_HOME:        "C:\Program Files\Java\jdk1.8.0_121"
Using CLASSPATH:       "C:\Program Files\Apache Software Foundation\Tomcat 9.0\bin\bootstrap.jar;C:\Program Files\Apache Software Foundation\Tomcat 

9.0\bin\tomcat-juli.jar"
16-Aug-2017 01:30:24.867 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/9.0.0.M22
16-Aug-2017 01:30:24.868 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Jun 21 2017 09:44:18 UTC
16-Aug-2017 01:30:24.868 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         9.0.0.0
16-Aug-2017 01:30:24.868 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Windows 10
16-Aug-2017 01:30:24.868 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            10.0
16-Aug-2017 01:30:24.868 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
16-Aug-2017 01:30:24.868 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             C:\Program Files\Java\jdk1.8.0_121\jre
16-Aug-2017 01:30:24.868 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_121-b13
16-Aug-2017 01:30:24.868 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
16-Aug-2017 01:30:24.868 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         C:\Users\Max\.IntelliJIdea2017.2\system\tomcat\Unnamed_websystique_20
16-Aug-2017 01:30:24.869 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         C:\Program Files\Apache Software Foundation\Tomcat 9.0
16-Aug-2017 01:30:24.869 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Users\Max\.IntelliJIdea2017.2\system\tomcat\Unnamed_websystique_20\conf\logging.properties
16-Aug-2017 01:30:24.869 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
16-Aug-2017 01:30:24.869 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
16-Aug-2017 01:30:24.869 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
16-Aug-2017 01:30:24.869 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
16-Aug-2017 01:30:24.869 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.authenticate=false
16-Aug-2017 01:30:24.869 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
16-Aug-2017 01:30:24.869 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
16-Aug-2017 01:30:24.869 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
16-Aug-2017 01:30:24.870 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Users\Max\.IntelliJIdea2017.2\system\tomcat\Unnamed_websystique_20
16-Aug-2017 01:30:24.870 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 9.0
16-Aug-2017 01:30:24.870 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=C:\Program Files\Apache Software Foundation\Tomcat 9.0\temp
16-Aug-2017 01:30:24.870 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_121\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\MySQL\MySQL Utilities 1.6\;C:\Program Files\Java\jdk1.8.0_121\bin;C:\Program Files (x86)\Microsoft VS Code\bin;C:\Users\Max\AppData\Local\Microsoft\WindowsApps;C:\sqlite-tools-win32-x86-3190200;;.]
16-Aug-2017 01:30:24.981 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
16-Aug-2017 01:30:24.995 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
16-Aug-2017 01:30:24.998 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
16-Aug-2017 01:30:25.000 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
16-Aug-2017 01:30:25.000 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 367 ms
16-Aug-2017 01:30:25.028 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
16-Aug-2017 01:30:25.028 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/9.0.0.M22
16-Aug-2017 01:30:25.035 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
16-Aug-2017 01:30:25.041 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
16-Aug-2017 01:30:25.044 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 43 ms
Connected to server
[2017-08-16 01:30:25,320] Artifact questions-websystique:war exploded: Artifact is being deployed, please wait...
16-Aug-2017 01:30:27.073 INFO [RMI TCP Connection(5)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
[2017-08-16 01:30:27,114] Artifact questions-websystique:war exploded: Artifact is deployed successfully
[2017-08-16 01:30:27,114] Artifact questions-websystique:war exploded: Deploy took 1 794 milliseconds
16-Aug-2017 01:30:35.036 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\manager]
16-Aug-2017 01:30:35.062 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\manager] has finished in [25] ms

这是工作版本的日志 - 春季4.0.6.RELEASE

HTTP Status 404 – Not Found

Type Status Report

Message /

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

Apache Tomcat/9.0.0.M22

2 个答案:

答案 0 :(得分:0)

您已在类级别上映射/,因此您无需在方法级别上再次映射它。您这样做意味着尝试访问//上的资源,这不仅是可能的。这是因为方法上的map与类上的map相关。

所以只需用

替换控制器类的mainPage方法上的@RequestMapping(value = "/")
@RequestMapping

或者

@RequestMapping(value = "")

或者

@RequestMapping(method = RequestMethod.GET)

答案 1 :(得分:0)

我找到了解决方案。我的.jsp文件中有2个没有taglibs。我添加了这个:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

Spring 4.0.6.RELEASE在某种程度上没有它们。