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

这篇文章主要介绍了Spring项目运行依赖spring-contex解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

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

一、pom.xml

4.0.0com.cnblogs.yjmyzzspring-boot-demo0.0.1-SNAPSHOT1.8org.springframeworkspring-context5.2.4.RELEASEmaven-compiler-plugin3.11.81.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-context的依赖关系如下:

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

相关文章

HashMap是Java中最常用的集合类框架,也是Java语言中非常典型...
在EffectiveJava中的第 36条中建议 用 EnumSet 替代位字段,...
介绍 注解是JDK1.5版本开始引入的一个特性,用于对代码进行说...
介绍 LinkedList同时实现了List接口和Deque接口,也就是说它...
介绍 TreeSet和TreeMap在Java里有着相同的实现,前者仅仅是对...
HashMap为什么线程不安全 put的不安全 由于多线程对HashMap进...