爲什麼找不到處理程序方法?彈簧寧靜配置錯誤
我有404錯誤,而使用彈簧寧靜,我已經嘗試過最答案,但由於某些原因,沒有什麼工作對我來說
這裏是我的配置:
我的web.xml配置
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/dispatcherServlet.xml
</param-value>
</init-param>
<init-param>
<param-name>javaEncoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
而且
我的調度員servlet.xml中配置
<mvc:resources mapping="/img/**" location="/img/*" />
<mvc:resources mapping="/js/**" location="/js/*" />
<mvc:resources mapping="/ajax/**" location="/ajax/*" />
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.crscube.etmf.*"
use-default-filters="false">
</context:component-scan>
<!-- <mvc:annotation-driven /> -->
<!-- Spring MVC @Controller 매핑 -->
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes" value="text/plain;charset=UTF-8" />
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<mvc:default-servlet-handler />
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
而且我的控制器源
@Controller
public class UserController {
protected final Logger logger = Logger.getLogger(getClass());
@Autowired
UserService userService = new UserServiceImpl();
@ResponseBody
@RequestMapping(value="/users", method=RequestMethod.GET)
public List<UserModel> getUser() throws Exception{
List<UserModel> listOfUser = userService.getUserList();
return listOfUser;
}
的問題是,請求http://localhost:8080/etmf/users給了我剛:
DEBUG({HTTP-BIO-8080-EXEC-2} DispatcherServlet.java [doService ]:819)[2017-02-07 19:36:08,466] - DispatcherServlet,名稱爲'dispatcher',處理[/ etmf/users]的GET請求 DEBUG({http-bio-8080-exec-2} AbstractHandlerMethodMapping.java [getHandlerInternal]:213)[2017-02-07 19:36:08,487] - 查找處理路徑/用戶的方法 DEBUG({HTTP的生物8080-EXEC-2} AbstractHandlerMethodMapping.java [getHandlerInternal]:223)[2017年2月7日19:36:08509] - 沒有找到[/用戶] DEBUG處理方法({ http-bio-8080-exec-2} AbstractUrlHandlerMapping.java [lookupHandler]:169)[2017-02-07 19:36:08,541] - 請求[/ users]的匹配模式是[/ **] DEBUG({ http-bio-8080-exec-2}摘要UrlHandlerMapping.java [lookupHandler]:193)[2017-02-07 19:36:08,564] - 請求[/ users]的URI模板變量是{} DEBUG({http- bio-8080-exec-2} AbstractUrlHandlerMapping.java [getHandlerInternal]:124)[2017-02-07 19:36:08,585] - 使用handler [org.springframework.web.servlet.resource將[/ users]映射到HandlerExecutionChain。 (http-bio-8080-exec-2)DispatcherServlet.java [doDispatch]:902)[2017-02-07 19:36:08,609] - [/ etmf/users]的Last-Modified值爲:-1 DEBUG({http-bio-8080-exec-2} DispatcherServlet.java [doDispatch]:957)[2017-02-07 19:36:08,631 ] - Null ModelAndView返回到名爲'dispatcher'的DispatcherServlet:假設HandlerAdapter完成請求處理 DEBUG({http-bio-8080-exec-2} FrameworkServlet.java [processRequest]:913)[2017-02-07 19:36 :08,650] - 成功完成請求
我該如何解決這個問題?
謝謝。
你'@ RequestMapping'值爲 「/用戶」,但你嘗試打開'/ etmf/users' – Optio
讓我知道如果下面的答案爲你工作.. –