spring4.x新特性 泛型依赖注入 springel表达式等,spring的两大核心概念 ioc 和 aop
(1)ioc:首先为什么会出现ioc 它解决了什么样的问题 ,追溯到定义与实现分离 :由接口——〉工厂——〉ioc
主要分离了业务代码和功能代码的实现,将bean之间的关联从实现统一接口 到 从工厂批量生产bean 再到所有bean直接与容器发生关系,从而解决bean之间的依赖 ioc的真正含义并非bean的创建权利,而是该bean实现功能的权利交由ioc容器,类似电脑硬件中的主板和cpu以及硬盘等硬件 均是通过cpu发送命令给主板芯片,然后由主板去调用其他硬件
(2)aop:面向切面编程 目前应用较少 也至写过一些例子,主要用在写日志方面 重点注解:@pointCut @after @before。
(3)spring 提倡的java配置:0配置 消灭xml文件。 spring boot 推荐配置方式 重点注解:@configuration @commentScan @bean 等
eg:
javaConfig
package com.wisely.highlight_spring4.ch1.javaconfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration //1
public class JavaConfig {
@Bean //2
public FunctionService functionService(){
return new FunctionService();
}
@Bean
public UseFunctionService useFunctionService(){
UseFunctionService useFunctionService = new UseFunctionService();
useFunctionService.setFunctionService(functionService()); //3
return useFunctionService;
}
// @Bean
// public UseFunctionService useFunctionService(FunctionService functionService){//4
// UseFunctionService useFunctionService = new UseFunctionService();
// useFunctionService.setFunctionService(functionService);
// return useFunctionService;
// }
}
----------------------------------------------main 函数--------------------------------------------------------------
public class Main {
public static void main(String[] args) {
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext(JavaConfig.class);
UseFunctionService useFunctionService = context.getBean(UseFunctionService.class);
System.out.println(useFunctionService.SayHello("java config"));
context.close();
}
}