spring in action 01

环境搭建

可以通过 eclipse -> help 菜单 -> Eclipse Marketplace, 然后选择 popular, 从中找到 Spring Tool Suite(STS)插件.

这样就安装了 STS 插件, 可以方便引入 Spring Boot 的 starter, 而 starter 会引入对应的依赖包和服务器, 这样快速帮我们搭建环境.

spring boot 可以不在使用 war 包来部署应用了.

A new interest in reactive programming aims to provide greater scalability and improved proformance with non-blocking operations.

传统方式

当有这两个 service, (inventory service 和 product service), 传统方式是: xml 或 java bean

<bean id="inventoryService"
class="com.example.InventoryService" />
<bean id="productService"
class="com.example.ProductService" />
<constructor-arg ref="inventoryService" />
</bean>
@Configuration
public class ServiceConfiguration {
@Bean
public InventoryService inventoryService() {
return new InventoryService();
}
@Bean
public ProductService productService() {
return new ProductService(inventoryService());
}
}

The @Configuration annotation indicates to Spring that this is a configuration class that will provide beans to the Spring application context.

 Automatic configuration has its roots in the Spring techniques known as autowiring and component scanning. 

component scanning: Spring can automatically discover components from an application's classpath and create them as beans.

autowiring: Spring automatically injects the components with the other beans that they depend on.

More recently, with introduction of Spring Boot, automatic configuration has gone well beyond component scanning and autowiring.

Spring Boot, the most well-know, is autoconfiguration. (所以spring boot 就更近一步, 不用设置了)

原文地址:https://www.cnblogs.com/moveofgod/p/12643891.html