2023 [localhost-startStop-1]运行tomcat时INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping未加载

时间:2016-03-11 20:13:45

标签: spring spring-mvc tomcat

如何配置加载此包

org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping

当我运行Tomcat时,我只得到以下所有内容:

0    [localhost-startStop-1] INFO  org.springframework.web.context.ContextLoader  - Root WebApplicationContext: initialization started
65   [localhost-startStop-1] INFO  org.springframework.web.context.support.XmlWebApplicationContext  - Refreshing Root WebApplicationContext: startup date [Fri Mar 11 21:55:33 EET 2016]; root of context hierarchy
366  [localhost-startStop-1] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader  - Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
470  [localhost-startStop-1] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader  - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-data.xml]
836  [localhost-startStop-1] INFO  org.springframework.context.support.PropertySourcesPlaceholderConfigurer  - Loading properties file from URL [file:/Volumes/Data/JavaEE/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/d14-spring_mvc/WEB-INF/classes/db_connection.properties]
1045 [localhost-startStop-1] INFO  org.springframework.web.context.ContextLoader  - Root WebApplicationContext: initialization completed in 1042 ms

所以我遇到了DispatcherServlet的问题,找不到与servlet的映射uri。

1735055 [http-nio-8001-exec-5] WARN  org.springframework.web.servlet.PageNotFound  - No mapping found for HTTP request with URI [/vietjob/tyopaikka.lista] in DispatcherServlet with name 'vietjob'

pom.xlm

<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>vjb.de</groupId>
    <artifactId>vietjob</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>vietjob Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <properties>
        <spring.version>4.0.0.RELEASE</spring.version>
    </properties>

    <dependencies>

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

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</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-test</artifactId>
            <version>${spring.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.5</version>
        </dependency>

        <dependency>
            <groupId>org.jumpmind.symmetric.jdbc</groupId>
            <artifactId>mariadb-java-client</artifactId>
            <version>1.1.1</version>
        </dependency>

        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>

        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.9.5</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.1.0.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <version>1.3</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.0.3.Final</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>vietjob</finalName>
    </build>
</project>

servlet.xml中

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

    <!-- Configures the @Controller programming model -->
    <mvc:annotation-driven />

    <context:component-scan base-package="vjb.de.vietjob" />

    <!-- Resolves view names to protected .jsp resources within the /WEB-INF/views 
        directory -->
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>


    <!-- Forwards requests to the "/" resource to the "welcome" view -->
    <mvc:view-controller path="/" view-name="index" />

    <!-- location of static content (images, js and css files) -->
    <mvc:resources mapping="/resources/**" location="/resources/" />

        <bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:lang" />
        <property name="defaultEncoding" value="UTF-8"/>
    </bean>

    <bean id="localeResolver"
        class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
        <property name="defaultLocale" value="en" />
    </bean>

    <mvc:interceptors>
        <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
            <property name="paramName" value="lang" />
        </bean>
    </mvc:interceptors>

</beans>

控制器

package vjb.de.vietjob.controller;

import java.util.List;

import javax.inject.Inject;
import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import vjb.de.vietjob.bean.Duuni;
import vjb.de.vietjob.bean.EhdokasImpl;
import vjb.de.vietjob.dao.DuuniDao;


@Controller
@RequestMapping(value = "/")
public class DuuniController {

    @Inject
    private DuuniDao duunidao;

    public DuuniDao getDuuniDao() {
        return this.duunidao;
    }

    public void setDuuniDao(DuuniDao duunidao) {
        this.duunidao = duunidao;
    }

    // Metodi näyttä kaikki työpaikat, jotka ovat oleva tietokannasta
    @RequestMapping(value = "/tyopaikka.lista", method = RequestMethod.GET)
    public String showDuuni(Model model) {
        List<Duuni> duunit = duunidao.showDuuni();
        model.addAttribute("duunit", duunit);
        return "duuni/tyopaikka";
    }

    // Metodi kotisivulle
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String returnIndex() {
        return "index";
    }

    // Metodi näyttää lisätietoja työpaikasta
    @RequestMapping(value = "/tyopaikka.lista/{id}", method = RequestMethod.GET)
    public String showYksiDuuni(
            @RequestParam(value = "id", required = false) Integer id,
            Model model) {
        Duuni duuni = duunidao.showYksiDuuni(id);
        model.addAttribute("duuni", duuni);
        return "duuni/yksipaikka";
    }

    // Metodi luo uusi ehdokkaan lomake

    @RequestMapping(value = "lomake.luo", method = RequestMethod.POST)
    public String getUusiEhdokas(
            @ModelAttribute(value = "ehdokas") @Valid EhdokasImpl ehdokas,
            BindingResult result) {
        return "lomake/ehdokas_lomake";
    }

}

控制器修改

package vjb.de.vietjob.controller;

import java.util.List;

import javax.inject.Inject;
import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import vjb.de.vietjob.bean.Duuni;
import vjb.de.vietjob.bean.EhdokasImpl;
import vjb.de.vietjob.dao.DuuniDao;


@Controller
/*@RequestMapping(value = "/")*/
public class DuuniController {

    @Inject
    private DuuniDao duunidao;

    public DuuniDao getDuuniDao() {
        return this.duunidao;
    }

    public void setDuuniDao(DuuniDao duunidao) {
        this.duunidao = duunidao;
    }

    // Metodi näyttä kaikki työpaikat, jotka ovat oleva tietokannasta
    @RequestMapping(value = "tyopaikka.lista", method = RequestMethod.GET)
    public String showDuuni(Model model) {
        List<Duuni> duunit = duunidao.showDuuni();
        model.addAttribute("duunit", duunit);
        return "duuni/tyopaikka";
    }

    @RequestMapping(value = "/tyopaikka.lista", method = RequestMethod.GET)
    public String showDuuni1(Model model) {
        List<Duuni> duunit = duunidao.showDuuni();
        model.addAttribute("duunit", duunit);
        return "duuni/tyopaikka";
    }

    @RequestMapping(value = "vietjob/tyopaikka.lista", method = RequestMethod.GET)
    public String showDuuni2(Model model) {
        List<Duuni> duunit = duunidao.showDuuni();
        model.addAttribute("duunit", duunit);
        return "duuni/tyopaikka";
    }

        @RequestMapping(value = "/vietjob/tyopaikka.lista", method = RequestMethod.GET)
        public String showDuuni3(Model model) {
            List<Duuni> duunit = duunidao.showDuuni();
            model.addAttribute("duunit", duunit);
            return "duuni/tyopaikka";
    }

    // Metodi kotisivulle
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String returnIndex() {
        return "index";
    }

}

1 个答案:

答案 0 :(得分:0)

您的控制器类具有顶级@RequestMapping("/"),请尝试将其更改为@RequestMapping("/vietjob")