Spring項(xiàng)目運(yùn)行依賴spring-contex解析
更新時(shí)間:2020年05月12日 10:06:42 作者:菩提樹下的楊過
這篇文章主要介紹了Spring項(xiàng)目運(yùn)行依賴spring-contex解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
spring項(xiàng)目跑起來,只需要spring-context這1個(gè)依賴項(xiàng)就行,參考下面:
一、pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cnblogs.yjmyzz</groupId>
<artifactId>spring-boot-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.4.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
二、示例代碼:
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();
}
}
項(xiàng)目結(jié)構(gòu):

spring-context的依賴關(guān)系如下:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
詳解SpringMVC中設(shè)置靜態(tài)資源不被攔截的問題
這篇文章主要介紹了詳解SpringMVC中設(shè)置靜態(tài)資源不被攔截的問題,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-02-02
struts2單個(gè)文件上傳的兩種實(shí)現(xiàn)方式
這篇文章主要介紹了struts2單個(gè)文件上傳的兩種實(shí)現(xiàn)方式,有需要的朋友可以參考一下2014-01-01
Spring框架應(yīng)用的權(quán)限控制系統(tǒng)詳解
在本篇文章里小編給大家整理的是關(guān)于基于Spring框架應(yīng)用的權(quán)限控制系統(tǒng)的研究和實(shí)現(xiàn),需要的朋友們可以學(xué)習(xí)下。2019-08-08
Java中通過sftp協(xié)議實(shí)現(xiàn)上傳下載的示例代碼
在java開發(fā)中遇到需要將linux系統(tǒng)中指定目錄下的文件下載到windows本地的需求,本文就來介紹Java中通過sftp協(xié)議實(shí)現(xiàn)上傳下載,具有一定的參考價(jià)值,感興趣的可以了解一下2024-06-06

