java.lang.AssertionError: Status expected:<200> but was:<404>我的Controller没有实例化

xiaoxiao2021-02-28  61

在SSM框架下,给Controller写test时,总是发生

java.lang.AssertionError: Status expected:<200> but was:<404>  at org.spring

头疼的要命.最后发现,连tomcat直接访问都不行.最后发现是没有搞清<context:component-scan>与<context:annotation-config>

以为写了<context:annotation-config>就不用写<context:component-scan>了.然而并不是.

annotation-config处理@autowired之类的注解(共有四类) 前提是注解作用的类已经被注册到spring容器里(bean id=“” class=“”) component-scan除了包含annotation-config的作用外,还能自动扫描和注册base-package下有@component之类注解的类,将其作为bean注册到spring容器里.

只写了<context:annotation-config>,结果Controller类并没有注册.

转载请注明原文地址: https://www.6miu.com/read-2631978.html

最新回复(0)