微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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的依赖关系如下:

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐