本文介绍了org.springframework.web.servlet.PageNotFound-在URI Spring 3中找不到HTTP请求的映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是spring mvc的新手,之前我是通过根软件包名称"localhost/spring"访问主页的,但我找不到我得到此错误的更改.Web.xml:
Im new to spring mvc, earlier I accessed homepage via root package name "localhost/spring", and I cant find out what i'd changed that i got this error.Web.xml:
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
主页控制器
@Controller
public class HomeController {
private UserServiceImpl userService;
@Inject
public HomeController(UserServiceImpl userService)
{
this.userService = userService;
}
@RequestMapping(value="/")
public String home(Model model) {
System.out.println("Sdfsd");
model.addAttribute("users", userService.getUsers());
return "home";
}
}
servlet-context.xml:
servlet-context.xml:
<annotation-driven />
<resources mapping="/resources/**" location="/resources/" />
<context:component-scan base-package="by.mvc.dao" />
<beans:bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<beans:property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<beans:property name="url" value="jdbc:hsqldb:hsql://localhost/user_db" />
<beans:property name="username" value="root" />
<beans:property name="password" value="root" />
<beans:property name="initialSize" value="5" />
<beans:property name="maxActive" value="10" />
</beans:bean>
<beans:bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<beans:property name="dataSource" ref="dataSource" />
<beans:property name="packagesToScan" value="by.mvc.dao" />
<beans:property name="hibernateProperties">
<beans:props>
<beans:prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</beans:prop>
</beans:props>
</beans:property>
</beans:bean>
<beans:bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<beans:property name="sessionFactory" ref="sessionFactory"/>
</beans:bean>
<beans:bean class="org.springframework.web.servlet.view.tiles2.TilesViewResolver"/>
<beans:bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<beans:property name="definitions">
<beans:list>
<beans:value>/WEB-INF/views/views.xml</beans:value>
</beans:list>
</beans:property>
</beans:bean>
有什么想法吗?谢谢
推荐答案
我相信应用程序可能不会扫描包含控制器的程序包.我看到一个dao软件包正在被扫描,但我想您不会将控制器放在那里.在您的配置中,扫描包含控制器的软件包.
I believe the application may not be scanning the package that contains the controllers. I see a dao package being scanned but I assume you wouldn't put your controllers there. In your configuration scan the package with the controllers.
<context:component-scan base-package="by.mvc.spring" />
这篇关于org.springframework.web.servlet.PageNotFound-在URI Spring 3中找不到HTTP请求的映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!