Spring项目运行依赖spring

网友投稿 289 2022-12-07


Spring项目运行依赖spring

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

一、pom.xlFcwLml

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

com.cnblogs.yjmyzz

spring-boot-demo

0.0.1-SNAPSHOT

1.8

org.springframework

spring-context&llFcwLt;/artifactId>

5.2.4.RELEASE

maven-compiler-plugin

3.1lFcwL

1.8

1.8

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

com.cnblogs.yjmyzz

spring-boot-demo

0.0.1-SNAPSHOT

1.8

org.springframework

spring-context&llFcwLt;/artifactId>

5.2.4.RELEASE

maven-compiler-plugin

3.1lFcwL

1.8

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


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Java操作Jenkins操作凭证(Credential)信息方式
下一篇:Spring aop失效的几种解决方案
相关文章

 发表评论

暂时没有评论,来抢沙发吧~