我是Spring新的mvc,早些時候,我通過根包名「localhost/spring」訪問主頁,我無法找到我我改變了我得到這個錯誤。 web.xml中:org.springframework.web.servlet.PageNotFound - 找不到使用URI的HTTP請求的映射Spring 3
<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中:
<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>
任何想法?謝謝
你使用的是什麼網址? –
localhost/spring - 基本包或localhost/SpringMvc的名稱 - 項目名稱 - 相同的結果 – kassie
還有一個問題,包含homecontroller的包是什麼? –