首先确定学习内容:
1)spring依赖注入框架学习
2)spring mvc框架学习
第一天首先学习spring IOC
一、环境搭建
jdk使用1.6以上
服务使用tomcat7
开发工具使用eclipse
引入jar包,下面是基本IOC必须引入的包
commons-logging
org.springframework.asm
org.springframework.beans
org.springframework.context.support
org.springframework.context
org.springframework.core
org.springframework.expression
然后配置applicationContext.xml放到src目录下
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
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-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!-- <context:annotation-config /> <context:component-scan base-package="com.artong"/>
自动扫描所有注解该路径 使用annotation 自动注册bean,并检查@Required,@Autowired的属性已被注入base-package为需要扫描的包(含所有子包) -->
<bean id="user" class="com.zyd.spring.User">
<property name="userName" value="测试zyd">
</property>
<property name="age" value="27">
</property>
<property name="gender" value="1">
</property>
</bean>
</beans>
User类如下:
package com.zyd.spring;
public class User {
private String userName;
private Integer age;
private Integer gender;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Integer getGender() {
return gender;
}
public void setGender(Integer gender) {
this.gender = gender;
}
}
Test中main方法如下:
public static void main(String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
"applicationContext.xml");
User user = (User) applicationContext.getBean("user");
System.out.println(user.getUserName());
}
打印结果为:测试zyd
***********************************************************************************************************
以上为第一天学习总结内容,第二天预备学习内容为复杂关系类引用或集合属性配置