一:降低java开发的复杂性,spring采取了4中关键策略
1:基于pojo的轻量级和最小侵入性编程;
2:基于依赖注入和面向接口实现松耦合;
3:基于切面和惯例进行声明式编程;
4:通过切面和模板减少样板式代码;
二:javaBeen的三种种定义方式
1:xml配置
<bean id="" class = "">(id是javabeen注入的是参考值,class是类文件的路径)
<constructor-arg ref = ""/>(ref可以使已经定义过的been id 或者是系统变量)
</bean>
获取javabeen:
import springframework.context.support.ClasspathXmlApplicationContext;
public class KnightMain{
public static void main(String[] args){
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("xml文件路径");
Test test = context.getBeen(Test.class);
context.close();
}
}
2:基于java的配置
package com.test
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import "定义的javabeen类路径"
@Configuration
public class KinghtConfig{
@Been
public Test test(){
return new Test();
}
}
3:基于注释
@Component 组件扫描默认是不开启的,我们需要显示配置一下spring,从而命令他去寻找@Component注解的类,并为其创建bean。开启方式有:在类文件中用@ComponentScan 或者在xml中配置<context:component-scan base-package=""/>
三:切面的xml配置
<bean id="aopTest" class = "">(id是javabeen注入的是参考值,class是类文件的路径)
<constructor-arg ref = ""/>(ref可以使已经定义过的been id 或者是系统变量)
</bean>
<aop:config>
<aop:aspect ref = "aopTest">
<aop:pointcut id = "embark" expression = "" />
<aop:before pointcut-ref = "embark" method = ""/>
<aop:after pointcut-ref = "embark" method = ""/>
</aop:aspect>
</aop:config>