뷰의 이름을 마지막으로 확인한 문자열을 반환하는 public function index()가있는 단일 컨트롤러 클래스 (MainController.class)와의 전쟁 프로젝트가 있습니다. "index.jsp"라는 단일 JSP로 전달되었습니다. 뷰는/main/webapp/WEB-INF/views/jsp /에 있습니다. MainController.java :Spring MVC 요청한 리소스를 사용할 수 없습니다.
@Controller
public class MainController
{
@Autowired
private ApplicationContextProvider mObjApplicationContextProvider;
@Autowired
private ScheduleService mObjScheduleService;
protected ApplicationContext getApplicationContext()
{
return(getApplicationContextProvider().getApplicationContext());
}
protected ApplicationContextProvider getApplicationContextProvider()
{
return(mObjApplicationContextProvider);
}
protected Object getBean(final Class<?> clsBean)
{
return(getApplicationContext().getBean(clsBean));
}
protected Object getBean(final String sBeanName)
{
return(getApplicationContext().getBean(sBeanName));
}
protected ScheduleService getScheduleService()
{
return(mObjScheduleService);
}
@RequestMapping(value="/")
public String index()
{
return("index");
}
}
의 index.jsp :
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Hello World!
</body>
</html>
내 구성 XML 파일 : 나는 내 브라우저에서 오류가 몇 가지 이유를 들어
<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/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<context:component-scan base-package="net.draconia.church" />
<bean class="net.draconia.ApplicationContextProvider" />
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver" />
<property name="url" value="jdbc:mysql:sql9.freemysqlhosting.net/sql9158326" />
<property name="username" value="sql9158326" />
<property name="password" value="MqX7sbacgB" />
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/views/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:annotation-driven />
</beans>
나는 "http://localhost:8080/Ushering/에 이동 ": 404 -"요청한 리소스를 사용할 수 없습니다. "
로그에서 아무 것도 찾을 수 없지만 필요한 경우 게시하여 어떤 파일이나 리소스를 사용할 수 없는지 알려줍니다. 하나의 로그 파일에서 컨트롤러에 대한 요청 매핑을 언급하기 때문에 컨트롤러를 찾을 수있는 것 같습니다. 뭐가 될수 있었는지?
편집 : WAR 파일은 pom 파일에 정의 된대로 Ushering이며 프로젝트의 이름으로 web.xml에도 정의되어 있으므로 컨텍스트가 Ushering이고 Spring 응용 프로그램 측면에있는 것으로 생각됩니다. 것들은/Ushering 이후에/Hello에 requestmapping을 설정하면 URL은 localhost : 8080/Ushering/Hello 여야합니다.
편집 : 내 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>CrunchifySpringMVCTutorial</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Ushering</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/Ushering-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Ushering</servlet-name>
<url-pattern>/s</url-pattern>
</servlet-mapping>
</web-app>
web.xml 파일을 게시 할 수 있습니까? – dennislloydjr
수정으로 추가했습니다. –
알았습니다! web.xml -/s를 url 패턴의 하단에 게시했을 때 오타가 나타났습니다. /이어야합니다 /. 나는 's'을 삭제하고, 깨끗한 컴파일 전쟁 : war-ed 그것을 예상하고있다 :-D 날 올바른 방향으로 파고 주셔서 감사합니다! –