我是Spring MVC的新手。我需要帮助。
我可以成功地使用Java EE Eclipse在WebLogic 10.3.6上部署我的应用程序。我可以在Controller的方法级别上成功运行映射的URL,如下所示。
http://localhost:7001/SpringMVCHibernateProject/hello
当我尝试上课时方法级别@RequestMapping注释它不起作用。 http://localhost:7001/SpringMVCHibernateProject/welcome/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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>SpringMVCHibernateProject</display-name>
<servlet>
<servlet-name>spring-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
弹簧调度-servlet.xml中
<?xml version="1.0" encoding="UTF-8"?>
<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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-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="au.com.snh.controllers" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
HelloAnnotationController.java
package au.com.snh.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("/welcome")
public class HelloAnnotationController {
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public ModelAndView sayHello(){
ModelAndView model = new ModelAndView("/pages/hello");
model.addObject("msg", "Hello Spring MVC World");
return model;
}
@RequestMapping("/hi")
public ModelAndView sayHi(){
ModelAndView model = new ModelAndView("/pages/hi");
model.addObject("msg", "Hi Spring MVC World");
return model;
}
}
可以请某人帮助解决可能出错的问题吗?
谢谢, 亚太区首席技术官Matt
答案 0 :(得分:0)
您错过了xml中的配置。<mvc:annotation-driven>