Spring笔记(未完)
★、要使用的jar
dist/spring.jarlib/jakarta-commons/commons-logging.jar
lib/aspectj/aspectjweaver.jarlib/aspectj/aspectjrt.jarlib/cglib/cglib-nodep-2.1_3.jar
lib/j2ee/common-annotabions.jar
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id="" name="code">ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml"});ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"d:/applicationContext.xml"});
<bean id="exampleBean" name="code"><bean id="exampleBean" name="code"><!-- the factory bean, which contains a method called createInstance() --><bean id="serviceLocator" name="code"><bean id="accountService" scope="prototype"/>
<bean id="person" lazy-init="true"></bean>
<bean id="person" init-method="init" destroy-method=”destroy”></bean>
public Person(){//构造函数}public void init(){//调用完构造函数会来调用这个方法,方法名是可以自定义的,可以在这里做一些事情,比如对资源进行打开,等}public void destroy(){}
ApplicationContext ctx = ……ctx.close();
package x.y;public class Foo { public Foo(Bar bar, Baz baz) { // ... }}
<beans> <bean name="foo" name="code">// 有参构造函数// 当使用简单类型时,比如<value>true<value>,Spring将无法知道该值的类型。不借助其他帮助,他将无法仅仅根据参数类型进行匹配package examples;public class ExampleBean { // No. of years to the calculate the Ultimate Answer private int years; // The Answer to Life, the Universe, and Everything private String ultimateAnswer; public ExampleBean(int years, String ultimateAnswer) { this.years = years; this.ultimateAnswer = ultimateAnswer; }}
<bean id="exampleBean" value="7500000"/> <constructor-arg type="java.lang.String" value="42"/></bean>
<bean id="exampleBean" value="7500000"/> <constructor-arg index="1" value="42"/></bean>
public class ExampleBean { private AnotherBean beanOne; private YetAnotherBean beanTwo; private int i; public void setBeanOne(AnotherBean beanOne) { this.beanOne = beanOne; } public void setBeanTwo(YetAnotherBean beanTwo) { this.beanTwo = beanTwo; } public void setIntegerProperty(int i) { this.i = i; } }
<bean id="exampleBean" ref="yetAnotherBean"/> <property name="integerProperty" value="1"/></bean><bean id="anotherExampleBean" class="examples.YetAnotherBean"/>