簡體   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