spring实战学习笔记一2015年6月7号

首先确定学习内容:

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

 

***********************************************************************************************************

以上为第一天学习总结内容,第二天预备学习内容为复杂关系类引用或集合属性配置

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值