• spring项目run起来的最小依赖


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

     一、pom.xml

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     3          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
     4     <modelVersion>4.0.0</modelVersion>
     5 
     6     <groupId>com.cnblogs.yjmyzz</groupId>
     7     <artifactId>spring-boot-demo</artifactId>
     8     <version>0.0.1-SNAPSHOT</version>
     9 
    10     <properties>
    11         <java.version>1.8</java.version>
    12     </properties>
    13 
    14     <dependencies>
    15         <dependency>
    16             <groupId>org.springframework</groupId>
    17             <artifactId>spring-context</artifactId>
    18             <version>5.2.4.RELEASE</version>
    19         </dependency>
    20     </dependencies>
    21 
    22     <build>
    23         <plugins>
    24             <plugin>
    25                 <artifactId>maven-compiler-plugin</artifactId>
    26                 <version>3.1</version>
    27                 <configuration>
    28                     <source>1.8</source>
    29                     <target>1.8</target>
    30                 </configuration>
    31             </plugin>
    32         </plugins>
    33     </build>
    34 
    35 </project>
    View Code

    二、示例代码:

     1 package com.cnblogs.yjmyzz.springbootdemo;
     2 
     3 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
     4 import org.springframework.context.annotation.ComponentScan;
     5 import org.springframework.context.annotation.Configuration;
     6 import org.springframework.stereotype.Service;
     7 
     8 /**
     9  * @author 菩提树下的杨过
    10  */
    11 @ComponentScan("com.cnblogs.yjmyzz")
    12 @Configuration
    13 public class SampleApplication {
    14 
    15     interface SampleService {
    16         void helloWorld();
    17     }
    18 
    19     @Service
    20     class SampleServiceImpl implements SampleService {
    21 
    22         @Override
    23         public void helloWorld() {
    24             System.out.println("hello spring");
    25         }
    26     }
    27 
    28     public static void main(String[] args) {
    29         AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SampleApplication.class);
    30         SampleService service = context.getBean(SampleService.class);
    31         service.helloWorld();
    32     }
    33 }
    View Code

    项目结构:

    spring-context的依赖关系如下:

  • 相关阅读:
    蓝桥杯 2014本科C++ B组 六角填数 枚举排列
    蓝桥杯 2014本科C++ B组 地宫取宝 DFS+记忆化搜索
    埃及分数 IDA*
    优先队列详解(转载)
    HDU 1242 Rescue BFS+优先队列
    HDU 1627 Krypton Factor
    2018中国机器人大赛服务机器人专项赛赛后总结
    OpenMP使用体验报告(概述)
    写在归程路上——2018ROBOCUP机器人世界杯中国赛
    ROS编译工作区缺少cv_bridge的问题解决
  • 原文地址:https://www.cnblogs.com/yjmyzz/p/spring-minimum-runtime-enrironment.html
Copyright © 2020-2023  润新知