Spring5学习(二)-spring projects之Spring Framework

Spring Framework

Core support for dependency injection(依赖注入), transaction management, web applications, data access, messaging, testing and more.


Introduction

The Spring Framework provides a comprehensive(综合的;广泛的;有理解力的) programming and configuration model for modern Java-based enterprise applications - on any kind of deployment platform. A key element(关键要素) of Spring is infrastructural(基础设施) support at the application level: Spring focuses on the "plumbing"(管道工程) of enterprise applications so that teams can focus on application-level business logic, without unnecessary ties to specific deployment environments.


Features

Dependency Injection
Aspect-Oriented(面向切面) Programming including Spring's declarative(声明的) transaction management
Spring MVC andSpring WebFlux web frameworks
Foundational support for JDBC, JPA, JMS
Much more…

All available features and modules are described in the Modules section of the reference documentation. Their maven/gradle coordinates are also described there.


Minimum requirements
JDK 8+ for Spring Framework 5.x
JDK 6+ for Spring Framework 4.x
JDK 5+ for Spring Framework 3.x


Quick Start

The recommended way to get started using spring-framework in your project is with a dependency management system – the snippet below can be copied and pasted into your build. Need help? See our getting started guides on building with Maven and Gradle.

current version:5.0.2

maven:

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>5.0.2.RELEASE</version>
    </dependency>
</dependencies>
gradle:

dependencies {
    compile 'org.springframework:spring-context:5.0.2.RELEASE'
}
Spring Framework includes a number of different modules. Here we are showing spring-context which provides core functionality(功能). Refer to the getting started guides on the right for other options.
Once you've set up your build with the spring-context dependency, you'll be able to do the following:

hello/MessageService.java

package hello;

public interface MessageService {
    String getMessage();
}
hello/MessagePrinter.java

package hello;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MessagePrinter {

    final private MessageService service;

    @Autowired
    public MessagePrinter(MessageService service) {
        this.service = service;
    }

    public void printMessage() {
        System.out.println(this.service.getMessage());
    }
}
hello/Application.java

package hello;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.*;

@Configuration
@ComponentScan
public class Application {

    @Bean
    MessageService mockMessageService() {
        return new MessageService() {
            public String getMessage() {
              return "Hello World!";
            }
        };
    }

  public static void main(String[] args) {
      ApplicationContext context = 
          new AnnotationConfigApplicationContext(Application.class);
      MessagePrinter printer = context.getBean(MessagePrinter.class);
      printer.printMessage();
  }
}
The example above shows the basic concept of dependency injection, the MessagePrinter is decoupled(减弱) from the MessageService implementation, with Spring Framework wiring(装配) everything together.



说明:

1. Spring WebFlux:Spring webflux 是一个新的非堵塞函数式 Reactive Web 框架,可以用来建立异步的,非阻塞,事件驱动的服务,并且扩展性非常好。(来自:LUPA

2. JPA:JPA是Java Persistence API的简称,中文名Java持久层API,是JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中。(来自:百度百科

3. JMS:Java平台上的专业技术规范。JMS即Java消息服务(Java Message Service)应用程序接口,是一个Java平台中关于面向消息中间件(MOM)的API,用于在两个应用程序之间,或分布式系统中发送消息,进行异步通信。Java消息服务是一个与具体平台无关的API,绝大多数MOM提供商都对JMS提供支持。(来自:百度百科




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jalen备忘录

谢谢~~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值