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

时间:2018-09-12 07:56:21

标签: java spring spring-mvc

我是Spring MVC的初学者,并且尝试创建Spring MVC应用程序时遇到以下错误

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

以下是文件:

Web.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注释。有人可以帮我解决这个问题。

3 个答案:

答案 0 :(得分:0)

以此更改您的servlet映射,然后尝试;

const httpObservable = this.http.get(urlThatWillRedirect).subscribe(data => ...) // JSON parser will fail

在您的<servlet-mapping> <servlet-name>appServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> 中,您的web.xmlurl-pattern。更改为/,以将请求发送到任何网址。

答案 1 :(得分:0)

尝试以下:

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

答案 2 :(得分:-1)

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