Spring项目运行怎么依赖spring-contex

小编这次要给大家分享的是Spring项目运行怎么依赖spring-contex,文章内容丰富,感兴趣的小伙伴可以来了解一下,希望大家阅读完这篇文章之后能够有所收获。

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名与空间、网站空间、营销软件、网站建设、光山网站维护、网站推广。

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

一、pom.xml

<&#63;xml version="1.0" encoding="UTF-8"&#63;>
<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();
  }
}

项目结构:

Spring项目运行怎么依赖spring-contex

spring-context的依赖关系如下:

Spring项目运行怎么依赖spring-contex

看完这篇关于Spring项目运行怎么依赖spring-contex的文章,如果觉得文章内容写得不错的话,可以把它分享出去给更多人看到。

网站名称:Spring项目运行怎么依赖spring-contex
转载来源:https://www.cdcxhl.com/article16/pdcodg.html

成都网站建设公司_创新互联,为您提供移动网站建设小程序开发企业网站制作微信公众号网站建设品牌网站制作

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

绵阳服务器托管