摘要: 1、用jdbc操作数据库举例,在导入了aop和spring依赖以外,导入sping-jdbc依赖,先创建配置类TxConfig,在类中注册了三个bean dataSource jdbcTemplate platformTransactionManager 还有@EnableTransactionMa 阅读全文
posted @ 2020-03-10 15:45 Arbitrary233 阅读(169) 评论(0) 推荐(0)
摘要: AOP-AOP功能测试 AOP : 【动态代理】指程序运行期间动态的将某段代码切入到制定方法位置进行运行的编程方式。 导入AOP模块:Spring AOP(spring-aspects) 定义一个业务逻辑类(Mathcalculator);在业务逻辑运行的时候将日志进行打印(方法之前、方法运行之后等 阅读全文
posted @ 2020-03-10 13:00 Arbitrary233 阅读(236) 评论(0) 推荐(0)
摘要: @Profile: Spring为我们提供的可以根据当前环境,动态的激活和切换一系列组件的功能; 开发环境develop、测试环境test、生产环境master 数据源:(/dev) (/test) (/master) @Profile:指定组件在哪个环境的情况下才能被注册到容器中,不指定,任何环境 阅读全文
posted @ 2020-03-10 11:22 Arbitrary233 阅读(208) 评论(0) 推荐(0)
摘要: 自动装配-Aware注入Spring底层组件&原理 Aware 接口,提供了类似回调函数的功能 自定义组件想要使用Spring 容器底层的一些组件(Application Context,Bean Factory);自定义组件需要实现xxxAware接口;在创建对象的时候,会调用接口规定的方法注入相 阅读全文
posted @ 2020-03-09 19:00 Arbitrary233 阅读(433) 评论(0) 推荐(0)
摘要: 1、@Autowired 标注在方法上 标注在方法,Spring容器创建当前对象,就会调用方法,完成赋值; 方法使用的参数,自定义类型的值从ioc容器中获取。配置类代码 @Configuration @Import({Boss.class, Car.class}) public class Main 阅读全文
posted @ 2020-03-09 16:52 Arbitrary233 阅读(4860) 评论(0) 推荐(2)
摘要: Spring 还支持使用@Resource(JSR250)和@Inject(JSR330)[Java规范的注解] AutowiredAnnotationBeanPostProcessor (后置处理器)完成解析自动装配功能 @Resource 可以和@Autowired一样实现自动注入功能,默认是按 阅读全文
posted @ 2020-03-09 16:34 Arbitrary233 阅读(247) 评论(0) 推荐(0)
摘要: 自动装配-@Autowired&@Qualifier&@Primary 自动装配:Spring 利用依赖注入(DI),完成对IOC容器中各个依赖关系赋值 @Autowired :自动注入 默认优先按照类型去容器中找对应的组件,applicationContext.getBean(BookReposi 阅读全文
posted @ 2020-03-09 16:21 Arbitrary233 阅读(290) 评论(0) 推荐(0)
摘要: 1、创建person类 public class Person { /* * 使用@Value赋值: * 1、基本数值 * 2、可以写SpEl;#{} * 3、可以写${}、取出配置文件中(例如properties文件)的值(运行环境变量里面的值) */ @Value("张三") private S 阅读全文
posted @ 2020-03-09 15:55 Arbitrary233 阅读(491) 评论(0) 推荐(0)
摘要: 1、创建Person类 public class Person { private String name; private Integer age; public Person() { super(); } public Person(String name, Integer age) { sup 阅读全文
posted @ 2020-03-08 15:03 Arbitrary233 阅读(875) 评论(0) 推荐(0)
摘要: 1、创建Bird类并注入容器中 @Component public class Bird { public Bird() { System.out.println("Bird的构造方法执行了"); } //对象构造并属性赋值后执行 @PostConstruct public void PostCon 阅读全文
posted @ 2020-03-08 11:54 Arbitrary233 阅读(304) 评论(0) 推荐(0)