最近在学习《SPring In Action》在用spring junit 做自动装配bean验证的时候,总出现Failed to load ApplicationContext 错误。查过很多文档与我的问题相差很多没有得到结果,只能自己解决。经过不断努力终于成功了。在这与大加分享一下我的经历。

一、spring 测试demo 项目——一个Java project 而已

创建一个Java project  添加相应的Jar包:

Junit + Spring Test 之使用@ComponentScan启用组件扫秒

二、创建Java类定义装配规则

Junit + Spring Test 之使用@ComponentScan启用组件扫秒

三、告诉Spring你的组件类,Spring会为你把事办得妥妥的^_^

Junit + Spring Test 之使用@ComponentScan启用组件扫秒

四、进行注入测试

Junit + Spring Test 之使用@ComponentScan启用组件扫秒

五、运行

Junit + Spring Test 之使用@ComponentScan启用组件扫秒

非常感谢大家的阅读,希望对像我一样的新手有所帮助^^。

相关文章:

  • 2021-10-01
  • 2022-12-23
  • 2021-12-14
  • 2021-12-21
  • 2021-05-03
  • 2022-03-05
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-18
  • 2022-12-23
  • 2023-01-10
  • 2021-11-24
  • 2021-08-14
相关资源
相似解决方案