美文网首页
Spring5源码阅读-01测试项目搭建

Spring5源码阅读-01测试项目搭建

作者: 惊天动地猪儿虫 | 来源:发表于2020-12-10 15:47 被阅读0次

从本周开始,逐步的根据项目学习下Spring5.0的源码

1 测试项目搭建

使用IDEA+MAVEN+Spring5.0搭建个最简单的测试项目


image.png

源码如下:

  • AppConfig
@Configuration
@ComponentScan("com.test")
public class AppConfig {
}
  • Dao
public interface Dao {
    void query();
}
  • IndexDao
@Component
public class IndexDao implements Dao{
    @Override
    public void query() {
        System.out.printf("IndexDao query");
    }
}
  • Service
public interface Service {
    void query();
}
  • IndexService
@Component
public class IndexService implements Service {

    @Autowired
    private Dao dao;

    @Override
    public void query() {
        System.out.printf("IndexService query");
        dao.query();
    }
}
  • TestMain
public class TestMain {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
        Service service = (Service) context.getBean("indexService");
        service.query();
    }
}
  • pom.xml
  <dependencies>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>5.0.0.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>5.0.0.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>5.0.0.RELEASE</version>
    </dependency>
  </dependencies>

2 测试结果

十二月 10, 2020 3:46:49 下午 org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@5a2e4553: startup date [Thu Dec 10 15:46:49 CST 2020]; root of context hierarchy
IndexService queryIndexDao query
Process finished with exit code 0

相关文章

网友评论

      本文标题:Spring5源码阅读-01测试项目搭建

      本文链接:https://www.haomeiwen.com/subject/svalgktx.html