我尝试用stackoverflow中遇到的所有解决方案来解决这个问题,但没有一个能为我工作
这是我的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"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<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/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>
</web-app>
这是我的servlet-context-xml:
<!-- Enable @Controller annotation support -->
<mvc:annotation-driven />
<!-- Esta etiqueta es para mapear carpetas dentro de src/main/webapp
de lo contrario el servidor no las reconoceria
-->
<!-- <mvc:resources mapping="/css/**" location="/css/" /> -->
<!-- Map simple view name such as "test" into /WEB-INF/PAGE/test.jsp -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/page/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
<property name="basename" value="views" />
</bean>
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"></bean>
<!-- Scan classpath for annotations (eg: @Service, @Repository etc) -->
<context:component-scan base-package="com.ieea.dao" />
<context:component-scan base-package="com.ieea.controller" />
<!-- Contenido agregador -->
<mvc:annotation-driven />
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
</bean>
<!-- Contenido agregador -->
<!-- JDBC Data Source. It is assumed you have MySQL running on localhost
port 3306 with username root and blank password. Change below if it's not
the case -->
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/******" />
<property name="username" value="*****" />
<property name="password" value="*****" />
<property name="validationQuery" value="SELECT 1" />
</bean>
<!-- Hibernate Session Factory -->
<bean id="mySessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="packagesToScan">
<array>
<value>com.ieea.domain</value>
</array>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
</props>
<!-- <value> hibernate.dialect=org.hibernate.dialect.MySQLDialect </value> -->
</property>
</bean>
<!-- Hibernate Transaction Manager -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="mySessionFactory" />
</bean>
<!-- Activates annotation based transaction management -->
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
控制器:
@Controller
public class UsuarioController {
@Autowired UsuarioDAOImpl usuarioDAO;
@RequestMapping(value = "lista", method = RequestMethod.GET)
public String testReporte(Model model) {
try {
System.out.println("Entre");
List<Usuario> lista = usuarioDAO.encontrarTodosUsuarios();
model.addAttribute("lista", lista);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return "index";
}
}
我认为问题出在web.xml或servlet-context.xml中 我不知道我的应用程序发生了什么,春天的其他应用程序永远不会导致这个问题。
org.springframework.web.servlet.PageNotFound:1108 - 在名为“appServlet”的DispatcherServlet中找不到带有URI [/ usuariosTest /]的HTTP请求的映射
答案 0 :(得分:1)
您可能没有提供&#34; /&#34;的请求映射。即启动网址。
放一个&#34; /&#34;您的控制器中的url映射。您需要先在服务器上部署它并启动服务器,然后在浏览器中点击应用程序URL。
@RequestMapping(value = "/", method = RequestMethod.GET)
public String testReporte(Model model) {
try {
System.out.println("Entre");
List<Usuario> lista = usuarioDAO.encontrarTodosUsuarios();
model.addAttribute("lista", lista);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return "index";
}