[英]JBoss AS 7.1.1 deployment issue
I installed JBoss AS 7.1.1 server. 我安装了JBoss AS 7.1.1服务器。 I created my project war file and put it under
[JBOSS_HOME]\\standalone\\deployments
folder. 我创建了项目war文件,并将其放在
[JBOSS_HOME]\\standalone\\deployments
文件夹下。
My application is Spring MVC and here is my web.xml 我的应用程序是Spring MVC,这是我的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 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. 在控制台日志中,spring加载了myapp-servlet.xml,并且所有请求映射均由我的控制器完成。 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类很简单:
@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. 如果我访问
http://localhost:8080/
则我的welcome.jsp将加载到网页中。
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: 但是问题是现在当我尝试使用以下URL
http://localhost:8080/myapp/welcome.jsp
我在网页中看到此错误:
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. 您应该使用当前配置中的
http://localhost:8080/myapp/welcome
访问您的应用。 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.) 您已将jsp文件放置在WEB-INF中,这意味着它们不能直接访问,这是spring框架中的标准做法(否则也应使用默认值)。
If you want to access welcome.jsp directly, you'll need to move it outside WEB-INF. 如果要直接访问welcome.jsp,则需要将其移至WEB-INF之外。 I would not do that however, requests should always go through servlets and not point directly at .jsps.
但是,我不会这样做,请求应该始终通过servlet而不是直接指向.jsps。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.