이름이있는 DispatcherServlet에서 URI가있는 HTTP 요청에 대한 매핑을 찾을 수 없습니다.
이 질문에 이미 답변이 있습니다.
이미 stackoverflow에 대한 거의 모든 관련 기사를 확인했지만 문제를 해결할 수 없습니다.
다음은 코드입니다 : web.xml :
<display-name>Spring3MVC</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</context-param>
<listener>
<listener-class> org.springframework.web.context.ContextLoaderListener </listener-class>
</listener>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.html</url-pattern>
<url-pattern>/</url-pattern>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
</web-app>
spring-servlet.xml :
<context:component-scan base-package="com.mycompany.elso" />
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<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/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
myController :
public class myController {
@RequestMapping("/hello")
public ModelAndView helloWorld() {
String message = "Hello World, Spring 3.0!";
return new ModelAndView("hello", "message", message);
}
}
웹 페이지 /index.jsp :
<html>
<head>
<title>Spring 3.0 MVC Series</title>
</head>
<body>
<a href="hello.html">Say Hello</a>
</body>
</html>
웹 페이지 /WEB-INF/jsp/hello.jsp :
<html>
<head>
<title>Spring 3.0 MVC Series: Hello World - ViralPatel.net</title>
</head>
<body>
${message}
</body>
</html>
따라서 appication을 시작하면 index.jsp가 올바르게로드되지만 href를 클릭하여 hello.jsp로 이동하면 404 오류가 발생하고 서버 로그에 다음과 같이 표시됩니다.
No mapping found for HTTP request with URI [/Elso/hello.html] in DispatcherServlet with name 'spring'
그런 기사를 수십 개 확인했지만 실수를 찾을 수 없습니다. 누구든지 그게 뭔지 아는 사람이 있나요?
@Controller
myController 클래스 위에 주석을 추가 하고 다음 URL을 시도 할 수 /<webappname>/my/hello.html
있습니다. 이는 myController 클래스의 각 RequestMapping org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping
앞에 / my 가 추가 되기 때문 입니다.
더하다
<mvc:default-servlet-handler/>
spring-servlet.xml에
사용하는 경우
<mvc:annotation-driven/>
spring-servlet.xml이 올바른지 확인하십시오.
<context:component-scan base-package="com.....controller" /> tag.
기본적으로 Java 코드에 주석을 사용한 모든 패키지를 포함해야합니다.
또한 컴포넌트 스캔 이 중복되지 않았는지 확인하십시오 (빈 발견 용). 구성 XML에 이미 요소가 포함되어있는 경우 @ComponentScan (basePackages = ... 주석이 달린 컨트롤러 클래스는 해당 주석을 제거해야합니다.
내 문제를 해결했습니다 : Java Build Path-> JRE 시스템 라이브러리-> 편집-> 대체 JRE->-> 마침
JDK 폴더로 구성되었으므로 예외가 발생했습니다.
생성 [PROJECT_NAME]\target\classes
여부를 확인하려면 디렉터리를 확인하십시오 myController.class
.
그렇지 않은 경우 컴파일 오류가 있는지 모든 Java 소스 코드를 확인하십시오.
확인하십시오
<mvc:annotation-driven/>
<context:component-scan base-package="com.hireartists.web.controllers"/>
컨트롤러가 포함 된 적절한 패키지를 가리 킵니다.
시험:
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
나를 위해 일했습니다!
Spring MVC 구성을 기반으로 Java 코드를 사용하는 DefaultServletHandlerConfigurer
경우 WebMvcConfigurerAdapter
객체 에서을 활성화하십시오 .
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
UR Bean xmlns를 확인하십시오.
나는 또한 비슷한 문제가 있었지만 mvc xmlns를 추가하여 해결했습니다.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<context:component-scan base-package="net.viralpatel.spring3.controller" />
<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/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
의 추가는 <mvc:annotation-driven/>
나를 위해 일했다. 줄 앞에 추가<context:component-scan ............/>
If you want to serve .html files, you must add this <mvc:default-servlet-handler />
in your spring config file. .html files are static. Hope that this can help someone.
Had the exact same error and it took me a long time trying to understand it. It is most likely down to compilation errors, the java classes did not get published in your servlet. Please check this by going in the server that you are using \tmp1\wtpwebapps[PROJECT_NAME]\WEB-INF\classes\ and try to find you controller classes to see whether or not they have been published. If not you need to get to the bottom of any compilation errors.
If you are using maven as build tool for project , build your project properly,your changes in the code and xml files are not reflecting after compilations.
If you depend on Spring Social, check that you have configured a Web Controller bean:
import org.springframework.context.annotation.Bean;
import org.springframework.social.connect.web.ConnectController;
import org.springframework.social.connect.ConnectionFactoryLocator;
import org.springframework.social.connect.ConnectionRepository;
...
@Bean
public ConnectController connectController(ConnectionFactoryLocator connectionFactoryLocator, ConnectionRepository connectionRepository) {
return new ConnectController(connectionFactoryLocator, connectionRepository);
}
if you are using maven then do run maven install command before you run your web app on a server as it will generate a class file for your controller and in my experience that is what your application has been missing.
I had the same issue and after lots of reserach I found the classes were not getting published in my target folder. So I had run the below two commands from cmd
- mvn clean install
- mvn package
Surprisingly I was able to access the page and error was gone. Same can be verified from target folder where you will be able to find the complied classes which were missing earlier.
It is not finding the controllers, this is basic issues. it can be due to following reasons.
A. inside WEB-INF folder you have file web.xml that refers to dispatcherServlet. Here it this case is mvc-config.xml
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
B. This mvc-config.xml file have namespaces and it has to scan the controllers.
<context:component-scan base-package="org.vimal.spring.controllers" />
<mvc:annotation-driven />
C. Check for the correctness of the package name where you have the controllers. It should work.
All Controllers must be Annotated with @Controller.
Add @Controller
to your controller or where ever you have the @RequestMapping
for you json end point.
This worked for me while deploying a similar application.
If you are using Maven , Add these to your pom.xml
<dependency>
<groupid>javax.servlet</groupid>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>runtime</scope>
<dependency>
<groupid>taglibs</groupid>
<artifactId>standard</artifactId>
<version>1.1.2</version>
<scope>runtime</scope>
I also faced the same issue, but after putting the namespace below, it works fine:
xmlns:mvc="http://www.springframework.org/schema/mvc"
Removing the Tomcat Server and adding new tomcat configuration in Eclipse resolved issue for me.
In pom.xml make sure packaging is set to war
like <packaging>war</packaging>
,not to jar or any thing else.
What is /Elso?
You try:
@RequestMapping("/Elso")
public class myController {
@RequestMapping("/hello")
public ModelAndView helloWorld() {
String message = "Hello World, Spring 3.0!";
return new ModelAndView("hello", "message", message);
}
}
'developer tip' 카테고리의 다른 글
WCF, ServiceHost 지시문의 서비스 특성 값을 찾을 수 없습니다. (0) | 2020.10.28 |
---|---|
라디오 버튼을 토글 버튼처럼 만드는 방법 (0) | 2020.10.28 |
정적 bower_components를 제공하도록 노드 익스프레스를 구성 하시겠습니까? (0) | 2020.10.28 |
Android Studio에서 내 프로젝트의 모든 하드 코딩 된 문자열을 어떻게 찾을 수 있습니까? (0) | 2020.10.28 |
rm ()으로 여러 객체 제거 (0) | 2020.10.28 |