随笔分类 - spring2
摘要:beans.xml:<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="ht
阅读全文
摘要:spring对于事务异常的处理//unchecked 运行期Exception spring默认会进行事务回滚 比如:RuntimeException//checked 用户Exception spring默认不会进行事务回滚 比如:Exception如何改变spring的这种默认事务行为?可以通过在方法上添加@Transactional(noRollbackFor=RuntimeException.class)让spring对于RuntimeException不回滚事务添加@Transactional(RollbackFor=Exception.class)让spring对于Exceptio
阅读全文
摘要:************************beans.xml************************<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframe
阅读全文
摘要:注解方式*******************beans.xml*******************<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.o
阅读全文
摘要:spring中aop功能的实现实际上是用cglib和jdk实现的,如果目标对象实现了接口那么用的是Jdk的方式实现,如果目标对象没有实现接口那么用的是cglib的方式实现。*******************PersonService.java*******************package blog.service; public interface PersonService { public String save(String name); public String update(String name,Integer userId); }
*************...
阅读全文
摘要:************beans.xml************<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context&
阅读全文
摘要:@Autowired默认按类型装配,它有一个required属性,默认为true,意思是这个字段或属性必须被装配,否则会报字段或属性装配异常,如果required设为false则可以将此字段或属性设置为null@Qualifier("personDao") 这个注解和@Autowired一起使用表示按名称进行查找@Autowired(required=true) @Qualifier("personDao")
阅读全文
摘要:beans.xml:<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocatio
阅读全文
摘要:package blog.service.impl; import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set; import blog.dao.PersonDao;
import blog.service.PersonService; public class PersonServiceBean ...
阅读全文
摘要:默认为singleton,prototype会在调用getBean()方法时,也就是第一次真正用到bean时才会实例化。所谓容器启动时指的是:ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");这句代码执行时。=========bean.xml=========<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframewor
阅读全文
摘要:===============PersonServiceBeanFactory.java===============package blog.service.impl; public class PersonServiceBeanFactory { public static PersonServiceBean createPersonServiceBean(){ return new PersonServiceBean(); } public PersonServiceBean createPersonServiceBean2(){ return new PersonSe...
阅读全文
摘要:案例:先加入dom4j的jar包。====================BlogClassPathXMLApplicationContext.java====================package junit.test; import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;.
阅读全文
摘要:案例:PersonService.java:package blog.service; public interface PersonService { public abstract void save(); }PersonServiceBean.java:package blog.service.impl; import blog.service.PersonService; public class PersonServiceBean implements PersonService { public void save(){ System.out.println(...
阅读全文