Spring项目运行依赖spring-contex解析

spring项目跑起来,只需要spring-context这1个依赖项就行,参考下面:

一、pom.xml



  4.0.0

  com.cnblogs.yjmyzz
  spring-boot-demo
  0.0.1-SNAPSHOT

  
    1.8
  

  
    
      org.springframework
      spring-context
      5.2.4.RELEASE
    
  

  
    
      
        maven-compiler-plugin
        3.1
        
          1.8
          1.8
        
      
    
  

二、示例代码:

package com.cnblogs.yjmyzz.springbootdemo;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;

/**
 * @author 菩提树下的杨过
 */
@ComponentScan("com.cnblogs.yjmyzz")
@Configuration
public class SampleApplication {

  interface SampleService {
    void helloWorld();
  }

  @Service
  class SampleServiceImpl implements SampleService {

    @Override
    public void helloWorld() {
      System.out.println("hello spring");
    }
  }

  public static void main(String[] args) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SampleApplication.class);
    SampleService service = context.getBean(SampleService.class);
    service.helloWorld();
  }
}

项目结构:

Spring项目运行依赖spring-contex解析_第1张图片

spring-context的依赖关系如下:

Spring项目运行依赖spring-contex解析_第2张图片

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

你可能感兴趣的:(Spring项目运行依赖spring-contex解析)