简体   繁体   中英

JBoss AS 7.1.1 deployment issue

I installed JBoss AS 7.1.1 server. I created my project war file and put it under [JBOSS_HOME]\\standalone\\deployments folder.

My application is Spring MVC and here is my web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
                        http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">

    <display-name>My WebApp</display-name>

    <!-- Configurations for the root application context (parent context) -->
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>

    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>/WEB-INF/classes/log4j.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/spring-jdbc.xml</param-value>
    </context-param>

    <!-- Controller -->
    <servlet>
        <servlet-name>myapp</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/myapp-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>myapp</servlet-name>
        <url-pattern>/myapp/*</url-pattern>
    </servlet-mapping>



    <session-config>
        <session-timeout>400</session-timeout>
    </session-config>

    <error-page>
        <exception-type>java.lang.Exception</exception-type>
        <location>/WEB-INF/jsp/Error.jsp</location>
    </error-page>

    <welcome-file-list> 
    <welcome-file>/WEB-INF/jsp/welcome.jsp</welcome-file>
    </welcome-file-list>

</web-app>

myapp-servlet.xml

<context:annotation-config />
<context:component-scan base-package="com.mypackage.mvc" />

<bean id="PropertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>       


<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />
</bean>

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

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
        <list>
            <ref bean="jsonConverter" />
        </list>
    </property>
</bean>

<bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
    <property name="supportedMediaTypes" value="application/json" />
</bean>

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <!-- the maximum file size in bytes = 10MB -->
    <property name="maxUploadSize" value="10485760" />
</bean>

In the console log myapp-servlet.xml gets loaded by spring and all the request mapping are done from my controller. Partial Log output:

12:27:13,440 INFO  [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] (MSC service thread 1-4) Mapped URL path [/myapp/welcome] onto handler 'myappController'
12:27:13,442 INFO  [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] (MSC service thread 1-4) Mapped URL path [/myapp/welcome.*] onto handler 'myappController'
12:27:13,444 INFO  [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] (MSC service thread 1-4) Mapped URL path [/myapp/welcome/] onto handler 'myappController'
12:27:13,527 INFO  [org.springframework.web.servlet.DispatcherServlet] (MSC service thread 1-4) FrameworkServlet 'myapp': initialization completed in 1028 ms
12:27:13,557 INFO  [org.jboss.web] (MSC service thread 1-4) JBAS018210: Registering web context: /myapp
12:27:13,565 INFO  [org.jboss.as] (MSC service thread 1-1) JBAS015951: Admin console listening on http://127.0.0.1:9990

My Controller class is simple:

@Controller
@RequestMapping("/myapp")
public class MyappController {

    private static Logger log = Logger.getLogger(MyappController.class);

    // @formatter:off
    /**
     * Welcome to MyApp
     * 
     * 
     * @return welcome.jsp Page
     * 
     * 
     */
    // @formatter:on
    @RequestMapping(value = "/welcome", method = RequestMethod.GET)
    public String welcome() {
        log.debug("welcome() called...");
        return "welcome";
    }

}

If I access http://localhost:8080/ then my welcome.jsp loads in webpage.

But the problem is Now when I try to access using the following url http://localhost:8080/myapp/welcome.jsp I see this error in webpage:

HTTP Status 404 - /myapp/welcome.jsp

--------------------------------------------------------------------------------

type Status report

message /myapp/welcome.jsp

description The requested resource (/myapp/welcome.jsp) is not available.


--------------------------------------------------------------------------------

JBoss Web/7.0.13.Final

Console log:

11:46:05,871 DEBUG [org.springframework.web.servlet.DispatcherServlet] (http-localhost-127.0.0.1-8080-1) DispatcherServlet with name 'myapp' processing GET request for [/myapp/welcome]
11:46:05,873 DEBUG [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (http-localhost-127.0.0.1-8080-1) Looking up handler method for path /welcome
11:46:05,875 DEBUG [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (http-localhost-127.0.0.1-8080-1) Did not find handler method for [/welcome]
11:46:05,876 WARN  [org.springframework.web.servlet.PageNotFound] (http-localhost-127.0.0.1-8080-1) No mapping found for HTTP request with URI [/myapp/welcome] in DispatcherServlet with name 'myapp'
11:46:05,878 DEBUG [org.springframework.web.servlet.DispatcherServlet] (http-localhost-127.0.0.1-8080-1) Successfully completed request

What could be wrong here?

You should access your app with http://localhost:8080/myapp/welcome in your current configuration. You have placed your jsp files inside WEB-INF, which means they're not directly accessible, which is the standard practice in spring framework (and reasonable default otherwise as well.)

If you want to access welcome.jsp directly, you'll need to move it outside WEB-INF. I would not do that however, requests should always go through servlets and not point directly at .jsps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM