前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >spring项目run起来的最小依赖

spring项目run起来的最小依赖

作者头像
菩提树下的杨过
发布2020-03-19 11:33:10
4660
发布2020-03-19 11:33:10
举报

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

一、pom.xml

代码语言:javascript
复制
 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>

二、示例代码:

代码语言:javascript
复制
 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 }

项目结构:

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-03-01 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档