摘要:import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.juni...
阅读全文
摘要:使用的spring-mvc版本是4.1.6,jackson版本是2.1.4 在spring-mvc配置文件中添加以下代码就行
阅读全文
摘要:首先需要添加c3p0包和jdbc包数据库:CREATE DATABASE IF NOT EXISTS `spring` /*!40100 DEFAULT CHARACTER SET utf8 */;USE `spring`;-- MySQL dump 10.13 Distrib 5.6.13, ...
阅读全文
摘要:直接看代码:package com.cn.spring.aop.impl;//加减乘除的接口类public interface ArithmeticCalculator { int add(int i, int j); int sub(int i, int j); int mul(...
阅读全文
摘要:直接看代码:package com.cn.spring.aop.impl;//加减乘除的接口类public interface ArithmeticCalculator { int add(int i, int j); int sub(int i, int j); int mul(...
阅读全文
摘要:通过使用@order注解指定切面的优先级,值越小,优先级越高代码:package com.cn.spring.aop.impl;//加减乘除的接口类public interface ArithmeticCalculator { int add(int i, int j); int sub...
阅读全文
摘要:在前置通知和后置通知的基础上加上返回通知&异常通知&环绕通知代码:package com.cn.spring.aop.impl;//加减乘除的接口类public interface ArithmeticCalculator { int add(int i, int j); int sub...
阅读全文
摘要:Spring后置通知,和前置通知类似,直接看代码:package com.cn.spring.aop.impl;//加减乘除的接口类public interface ArithmeticCalculator { int add(int i, int j); int sub(int i, ...
阅读全文
摘要:1).加入jar包:下载地址 spring-beans-4.1.6.RELEASE.jar commons-logging-1.1.3.jar spring-context-4.1.6.RELEASE.jar spring-core-4.1.6.RELEASE.jar spring-exp...
阅读全文
摘要:为什么需要AOP?先来看一段代码:package com.cn.spring.aop.helloworld;//加减乘除的接口类public interface ArithmeticCalculator { int add(int i, int j); int sub(int i, in...
阅读全文
摘要:Spring 4.x中可以为子类注入子类对应的泛型类型的成员变量的引用BaseService:有RoleService和UserService两的子类BaseRepepositry:有UserRepository和RoleRepositry两个子类由于 BaseService和 BaseRepepo...
阅读全文
摘要:下面将对13Spring通过注解配置Bean(1)的中Repository、Service、Controller通过注解方式来建立关联。元素还会自动注册AutowiredAnnotationBeanPostProcessor后置处理器实例,该实例可以自动装配具有@Autowired属性。@Autow...
阅读全文
摘要:配置Bean的形式:基于XML文件的方式;基于注解的方式(基于注解配置Bean;基于注解来装配Bean的属性)下面介绍基于注解的方式来配置Bean。——组件扫描(component scanning):Spring能够从classpath下自动扫描,侦测和实例化具有特定注解的组件。——特定组件包括:...
阅读全文
摘要:为啥要使用FactoryBean: 在配置Bean的时候,需要用到IOC容器中的其它Bean,这个时候使用FactoryBean配置最合适。public class Car { private String brand; private double price; publi...
阅读全文
摘要:通过工厂方法配置Bean暴扣静态工厂方法和实例工厂方法。1.静态工厂方法 调用静态工厂方法创建Bean是将对象创建的过程封装到静态方法中,当客户端需要对象时,只需要简单的调用静态方法,而不去关心创建对象的细节。 要声明通过静态方法创建的Bean,需要在Bean的class属性里指定拥有该工厂的方法...
阅读全文
摘要:Spring IOC容器可以管理Bean的生命周期,允许在Bean声明周期的特定点执行定制的任务。Spring IOC容器对Bean的生命周期进行管理的过程。1.通过构造器或工厂方法创建Bean实例2.位Bean的属性设置值和对其他Bean的引用3.调用Bean的初始化方法4.使用Bean5.当容器...
阅读全文