Application run failed——p18集做谷粒商城时遇到的测试类启动不起来,报错:Caused by: java.lang.IllegalStateException

启动测试类,首先报错:java.lang.NullPointerException 空指针异常

代码如图:

后来加上:

@SpringBootTest(classes = GulimallProductApplication.class)

 空指针异常解决:

 但这个问题解决后,新的问题又来了:

运行GulimallProductApplicationTest报错:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-09-23 12:42:56.308 ERROR 22272 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'categoryController' method 
public com.atguigu.common.utils.R com.atguigu.gulimall.product.controller.CategoryController.update(com.atguigu.gulimall.product.entity.CategoryEntity)
to { /update}: There is already 'attrAttrgroupRelationController' bean method

有方法说应该先把主模块启动类启动后,再运行测试类。但运行GulimallProductApplication依旧报错:

2021-09-23 12:42:56.309 ERROR 22272 --- [           main] o.s.test.context.TestContextManager      : Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@4b14c583] to prepare test instance [com.atguigu.gulimall.product.GulimallProductApplicationTests@28da7d11]

java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125) ~[spring-test-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) ~[spring-test-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190) ~[spring-test-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132) ~[spring-test-5.1.9.RELEASE.jar:5.1.9.RELEASE]

解决方法:

找了好久突然发现自己粗心把代码生成器中@RequestMapping注解不小心注释掉了

 

于是在每个controller层的文件下都添加@RequestMapping注解,问题解决。

@RequestMapping("product/attr")

 

 

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值