繁体   English   中英

在调度程序 servlet 中找不到映射错误

[英]No mapping found error in dispatcher servlet

我是 Spring MVC 的初学者,在尝试创建Spring MVC应用程序时出现以下错误

no mapping found for http request with uri [/SpringMVCHibernateCRUD] in dispatcherservlet 'appServlet'

以下是文件:

网页.xml

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>


<!-- Processes application requests -->
<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>

servlet-context.xml

      <context:component-scan base-package="com.jwt" />

<!-- Getting Database properties -->
<context:property-placeholder location="classpath:application.properties" />

<mvc:annotation-driven />

<!-- Specifying the Resource location to load JS, CSS, Images etc -->
<mvc:resources mapping="/resources/**" location="/resources/" />

<!-- View Resolver -->
<bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/pages/" />
    <property name="suffix" value=".jsp" />
</bean>

<!-- Transaction -->
<bean id="transactionManager"

 class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />
 </beans>

编辑:

控制器

 @Controller
 public class EmployeeController {

 private static final Logger logger = Logger
        .getLogger(EmployeeController.class);

 public EmployeeController() {
    System.out.println("EmployeeController()");
 }

 @Autowired
 private EmployeeService employeeService;

 @RequestMapping(value = "/")
 public ModelAndView listEmployee(ModelAndView model) throws IOException {
    List<Employee> listEmployee = employeeService.getAllEmployees();
    model.addObject("listEmployee", listEmployee);
    model.setViewName("home");
    return model;
 }

/更改为/*并没有解决问题,我已经在控制器上添加了@controller注释。 有人可以帮我解决这个问题。

使用此更改您的 servlet 映射并尝试;

<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

在您的web.xml ,您的url-pattern仅为/ 更改为/*以向任何 url 发送请求。

试试下面:

<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/app/*</url-pattern>
</servlet-mapping>

感谢您的回答,显然一个简单的清理和构建解决了我的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM