亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法訪問 Spring 控制器

無法訪問 Spring 控制器

慕妹3146593 2022-01-12 14:46:36
我正在嘗試從頭開始創建一個非?;镜膽贸绦虻?Spring RESTful API,但我無法訪問控制器。我可以訪問 JSP 文件但不能訪問控制器。我也嘗試過注釋,@RestController但它沒有用。我在Tomcat 8上運行。錯誤是:源服務器沒有找到目標資源的當前表示或不愿意透露存在的表示。WEB.xml    <?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">  <listener>    <listener-class>        org.springframework.web.context.ContextLoaderListener    </listener-class>  </listener>      <servlet>        <servlet-name>dispatcher</servlet-name>        <servlet-class>            org.springframework.web.servlet.DispatcherServlet        </servlet-class>        <load-on-startup>1</load-on-startup>    </servlet>    <servlet-mapping>        <servlet-name>dispatcher</servlet-name>        <url-pattern>/</url-pattern>    </servlet-mapping></web-app>調度程序-servlet.xml    <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"    xmlns:mvc="http://www.springframework.org/schema/mvc"    xmlns:context="http://www.springframework.org/schema/context"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="        http://www.springframework.org/schema/beans             http://www.springframework.org/schema/beans/spring-beans.xsd        http://www.springframework.org/schema/mvc         http://www.springframework.org/schema/mvc/spring-mvc.xsd        http://www.springframework.org/schema/context         http://www.springframework.org/schema/context/spring-context.xsd">    <mvc:annotation-driven />    <context:component-scan        base-package="com.controller />    <mvc:default-servlet-handler /></beans>
查看完整描述

2 回答

?
墨色風雨

TA貢獻1853條經驗 獲得超6個贊

如果要單獨創建應用程序上下文,則應提供上下文參數和值作為 context.xml 文件的位置。


<listener>

    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

<context-param>

    <param-name>contextConfigLocation</param-name>

    <param-value>/WEB-INF/application-context.xml</param-value>

</context-param>

對于您的錯誤,控制器無法訪問,可能是由于:-


<context:component-scan

    base-package="com.controller />

檢查您是否編寫了正確的基本包名稱或嘗試使用


<context:component-scan base-package="..package name..">

<context:include-filter expression="org.springframework.stereotype.Controller" type="annotation"/>

</context:component-scan>

希望能幫助到你。


查看完整回答
反對 回復 2022-01-12
?
慕姐4208626

TA貢獻1852條經驗 獲得超7個贊

從 web.xml 中刪除偵聽器,因為您只有一個上下文 xml。如果要加載多個上下文 xml,請添加偵聽器和上下文參數。


查看完整回答
反對 回復 2022-01-12
  • 2 回答
  • 0 關注
  • 201 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號