1.Spring官网初探
日常生活中,我们发现什么东西都是原装的好,所以无论学习编程语言还是框架,与其花大量的时间搜资料,不如静心好好学习官网,官网是最好的学习资料(权威、准确的第一手材料),spring的官方网址:https://spring.io/
官网的界面简洁清新,导航很明确,进入projects
从配置到安全,Web应用到大数据 - 无论您的应用程序有什么样的需求,都有一个Spring Project来帮助您构建它,spring的涵盖面是很宽广的,你需要什么可以在上图所示的页面中查找,本页很清晰,很容易找到spring framework, 还有一段英文介绍provides core support for dependency injection, transaction management, web apps, data access, messaging and more.(提供了核心功能依赖注入、事务管理、web应用、数据访问、远程访问等等)
选择spring framework
本页有介绍、特点说明、spring框架版本对jdk的要求、以及如果使用Maven或 Gradle构建项目的话,官网还提供了相应的范例向导。
最重要是在特征下面的这段话,需要注意:
All avaible features and modules are described in the Modules section of the reference documentation. Their maven/gradle coordinates are also described there.
这段话很清晰的告诉我们点击这段话上的链接,专门有关于所有特征和模块以及各模块之间关系的介绍。这是一页有关于spring框架的很详细的介绍,包括spring的Jar包链接以及说明,所以很有必要认真看一看。
Spring框架简介
Spring框架为基于Java的企业应用程序提供了全面的编程和配置模型,Spring的一个关键要素是应用程序级别的基础架构支持:Spring侧重于企业应用程序的“管道”,以便团队可以专注于应用程序级别的业务逻辑,而不必与特定的部署环境形成不必要的联系。
Spring框架特点
- 依赖注入
- AOP面向切面的编程,包括Spring的声明式事务管理
- Spring MVC和Spring WebFlux Web框架
- 对JDBC,JPA,JMS的基础支持
开始使用
官方推荐在项目中使用spring-framework的方法是使用依赖管理系统 - 下面的代码片段可以复制并粘贴到您的构建中。
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框架包含许多不同的模块。这里我们展示了提供核心功能的spring-context模块
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();
}
}
日常生活中,我们发现什么东西都是原装的好,所以无论学习编程语言还是框架,与其花大量的时间搜资料,不如静心好好学习官网,官网是最好的学习资料(权威、准确的第一手材料),spring的官方网址:https://spring.io/
官网的界面简洁清新,导航很明确,进入projects
从配置到安全,Web应用到大数据 - 无论您的应用程序有什么样的需求,都有一个Spring Project来帮助您构建它,spring的涵盖面是很宽广的,你需要什么可以在上图所示的页面中查找,本页很清晰,很容易找到spring framework, 还有一段英文介绍provides core support for dependency injection, transaction management, web apps, data access, messaging and more.(提供了核心功能依赖注入、事务管理、web应用、数据访问、远程访问等等)
选择spring framework
本页有介绍、特点说明、spring框架版本对jdk的要求、以及如果使用Maven或 Gradle构建项目的话,官网还提供了相应的范例向导。
最重要是在特征下面的这段话,需要注意:
All avaible features and modules are described in the Modules section of the reference documentation. Their maven/gradle coordinates are also described there.
这段话很清晰的告诉我们点击这段话上的链接,专门有关于所有特征和模块以及各模块之间关系的介绍。这是一页有关于spring框架的很详细的介绍,包括spring的Jar包链接以及说明,所以很有必要认真看一看。
Spring框架简介
Spring框架为基于Java的企业应用程序提供了全面的编程和配置模型,Spring的一个关键要素是应用程序级别的基础架构支持:Spring侧重于企业应用程序的“管道”,以便团队可以专注于应用程序级别的业务逻辑,而不必与特定的部署环境形成不必要的联系。
Spring框架特点
- 依赖注入
- AOP面向切面的编程,包括Spring的声明式事务管理
- Spring MVC和Spring WebFlux Web框架
- 对JDBC,JPA,JMS的基础支持
开始使用
官方推荐在项目中使用spring-framework的方法是使用依赖管理系统 - 下面的代码片段可以复制并粘贴到您的构建中。
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框架包含许多不同的模块。这里我们展示了提供核心功能的spring-context模块
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();
}
}