Невозможно получить второе приложение Spring MVC для запуска в STS. - PullRequest
0 голосов
/ 04 января 2012

Я использую это руководство:

http://blog.springsource.org/2011/01/04/green-beans-getting-started-with-spring-mvc/

для запуска приложения Spring MVC с использованием набора инструментов Spring 3.0 (sts).

Работает нормально, когдаодно приложение (BareMvc) развернуто и использует этот URL:

http://localhost:8080/BareMvc/

Однако, если я попытаюсь развернуть второе (AnotherMvcProject), используя этот URL:

http://localhost:8080/AnotherMvcProject/

Возвращает ошибку 404 Страница не найдена, и консоль отображает следующее сообщение об ошибке:

ARN: org.springframework.web.servlet.PageNotFound - сопоставление не найдено дляHTTP-запрос с URI [/ AnotherMvcProject /] в DispatcherServlet с именем 'appServlet'

Кроме того, журнал показывает, что он развертывается:

Jan 3, 2012 2:24:07 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor AnotherMvcProject.xml from /Users/myname/springsource/vfabric-tc-server-developer-2.6.1.RELEASE/spring-insight-instance/conf/Catalina/localhost

Вот файл web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">

    <!-- 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/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

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

</web-app>

Вот ServletContext:

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

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

    <context:component-scan base-package="xyz.mvc.project" />

</beans:beans>

Вот код контроллера:

/**
 * Handles requests for the application home page.
 */
@Controller
public class HomeController {

    private static final Logger logger = LoggerFactory.getLogger(HomeController.class);

    /**
     * Simply selects the home view to render by returning its name.
     */
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String home(Locale locale, Model model) {
        logger.info("Welcome home! the client locale is "+ locale.toString());

        Date date = new Date();
        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);

        String formattedDate = dateFormat.format(date);

        model.addAttribute("serverTime", formattedDate );

        return "home";
    }

}

Код идентичен BareMvc, за исключением имени пакета.xyz.sample.baremvc против xyz.mvc.project.

Мне не ясно, как определяется сопоставление имени приложения с механизмом сервлета.Похоже, это может быть pom.xml, проект, но они также согласуются:

groupId=xyz.sample
m2e.projectName=BareMvc

groupId=xyz.mvc
m2e.projectName=AnotherMvcProject

Я в тупике.Какие-нибудь мысли?

1 Ответ

0 голосов
/ 06 января 2012

Для дальнейшего использования - просто очистка проекта решила проблему.

...