码迷,mamicode.com
首页 > 编程语言 > 详细

spring项目run起来的最小依赖

时间:2020-03-02 00:50:28      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:EDA   run   stat   version   菩提   blog   frame   log   nconf   

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项目run起来的最小依赖

标签:EDA   run   stat   version   菩提   blog   frame   log   nconf   

原文地址:https://www.cnblogs.com/yjmyzz/p/spring-minimum-runtime-enrironment.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!