20160125--Spring
package com.hanqi;
import java.util.*;
import com.hanqi.User;
public class HelloWorld {
public HelloWorld()
{
}
public HelloWorld(String name)
{
this.name = name;
}
private User user;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
System.out.println("设置name = " + name);
this.name = name;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public void sayHello()
{
System.out.println("Hello " + name + " " + user);
}
private List<User> userlist;
public List<User> getUserlist() {
return userlist;
}
public void setUserlist(List<User> userlist) {
this.userlist = userlist;
}
}
HelloWorld
<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- autowire="byName" bean的id和要装配的属性名一致,根据属性名进行自动装配 -->
<!-- <bean id="helloWorld" autowire="byName" class="com.hanqi.HelloWorld"> --> <!-- autowire="byType" 根据bean的类型进行自动匹配的,要求同一类型的bean只能被定义一个 -->
<!-- <bean id="helloWorld" autowire="byType" class="com.hanqi.HelloWorld"> --> <bean id="helloWorld" scope="prototype" class="com.hanqi.HelloWorld" p:user-ref="user2">
<property name="name" value="测试1"></property>
<property name="userlist">
<list >
<ref bean="user1" />
</list>
</property>
</bean> <bean id="user1" class="com.hanqi.User"> <property name="name" value="测试3"></property>
<property name="age" value="20"></property>
<property name="sex" value="男"></property> </bean> <bean id="user2" class="com.hanqi.User" p:name="测试4" p:age="30" p:sex="男">
</bean> </beans>
applicationContext.xml
package com.hanqi;
public class User {
public User()
{
}
@Override
public String toString() {
return "User [name=" + name + ", age=" + age + ", sex=" + sex + "]";
}
public User(String name, int age, String sex) {
super();
this.name = name;
this.age = age;
this.sex = sex;
}
public User(String name, String sex, int age) {
super();
this.name = name;
this.age = age;
this.sex = sex;
}
private String name;
private int age;
private String sex;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
User
package com.hanqi; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class TestSp { public static void main(String[] args) { //构建容器
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml"); HelloWorld hw = (HelloWorld)ac.getBean("helloWorld"); hw.sayHello(); HelloWorld hw1 = (HelloWorld)ac.getBean("helloWorld");
System.out.println(hw == hw1); } }
TestSp
20160125--Spring的更多相关文章
- Java缓存相关memcached、redis、guava、Spring Cache的使用
随笔分类 - Java缓存相关 主要记录memcached.redis.guava.Spring Cache的使用 第十二章 redis-cluster搭建(redis-3.2.5) 摘要: redi ...
- 基于spring注解AOP的异常处理
一.前言 项目刚刚开发的时候,并没有做好充足的准备.开发到一定程度的时候才会想到还有一些问题没有解决.就比如今天我要说的一个问题:异常的处理.写程序的时候一般都会通过try...catch...fin ...
- 玩转spring boot——快速开始
开发环境: IED环境:Eclipse JDK版本:1.8 maven版本:3.3.9 一.创建一个spring boot的mcv web应用程序 打开Eclipse,新建Maven项目 选择quic ...
- Spring基于AOP的事务管理
Spring基于AOP的事务管理 事务 事务是一系列动作,这一系列动作综合在一起组成一个完整的工作单元,如果有任何一个动作执行失败,那么事务 ...
- [Spring]IoC容器之进击的注解
先啰嗦两句: 第一次在博客园使用markdown编辑,感觉渲染样式差强人意,还是github的样式比较顺眼. 概述 Spring2.5 引入了注解. 于是,一个问题产生了:使用注解方式注入 JavaB ...
- 学习AOP之透过Spring的Ioc理解Advisor
花了几天时间来学习Spring,突然明白一个问题,就是看书不能让人理解Spring,一方面要结合使用场景,另一方面要阅读源代码,这种方式理解起来事半功倍.那看书有什么用呢?主要还是扩展视野,毕竟书是别 ...
- 学习AOP之深入一点Spring Aop
上一篇<学习AOP之认识一下SpringAOP>中大体的了解了代理.动态代理及SpringAop的知识.因为写的篇幅长了点所以还是再写一篇吧.接下来开始深入一点Spring aop的一些实 ...
- 学习AOP之认识一下Spring AOP
心碎之事 要说知道AOP这个词倒是很久很久以前了,但是直到今天我也不敢说非常的理解它,其中的各种概念即抽象又太拗口. 在几次面试中都被问及AOP,但是真的没有答上来,或者都在面上,这给面试官的感觉就是 ...
- 为什么做java的web开发我们会使用struts2,springMVC和spring这样的框架?
今年我一直在思考web开发里的前后端分离的问题,到了现在也颇有点心得了,随着这个问题的深入,再加以现在公司很多web项目的控制层的技术框架由struts2迁移到springMVC,我突然有了一个新的疑 ...
- Spring之旅(2)
Spring简化Java的下一个理念:基于切面的声明式编程 3.应用切面 依赖注入的目的是让相互协作的组件保持松散耦合:而AOP编程允许你把遍布应用各处的功能分离出来形成可重用的组件. AOP面向切面 ...
随机推荐
- Codeforces Round #312 (Div. 2) ABC题解
[比赛链接]click here~~ A. Lala Land and Apple Trees: [题意]: AMR住在拉拉土地. 拉拉土地是一个很漂亮的国家,位于坐标线.拉拉土地是与著名的苹果树越来 ...
- java PriorityBlockingQueue 基于优先级队列,的读出操作可以阻止.
java PriorityBlockingQueue 基于优先级队列.的读出操作可以阻止. package org.rui.thread.newc; import java.util.ArrayLis ...
- C++ STL源代码学习(map,set内部heap篇)
stl_heap.h ///STL中使用的是大顶堆 /// Heap-manipulation functions: push_heap, pop_heap, make_heap, sort_heap ...
- 【最大流,二分图匹配】【hdu2063】【过山车】
题意:裸的求二分图匹配 建立一个源点 连向一边所有的点 容量为1; 另外一边点都连向汇点 容量为1; 二分图的边容量也为1 源点汇点求一遍最大流即可 #include <cstdio> ...
- netty demo
Netty 4.0 demo netty是一个异步,事件驱动的网络编程框架&工具,使用netty,可以快速开发从可维护,高性能的协议服务和客户端应用.是一个继mina之后,一个非常受欢迎的 ...
- SVG-1
<rect>矩形 <circle>圆 <ellipse>椭圆 <line>直线 <polyline>折线 <polygon>标签 ...
- 事件:target与currentTarget区别
target在事件流的目标阶段:currentTarget在事件流的捕获,目标及冒泡阶段.只有当事件流处在目标阶段的时候,两个的指向才是一样的, 而当处于捕获和冒泡阶段的时候,target指向被单击的 ...
- 30个你不可不知的CSS选择器
30个你不可不知的CSS选择器 一.五大基本选择符 1. *(通配符)*通配符选择器,经常用于css reset(样式重置),清理标签的默认样式,但现在一般不提倡直接使用*了,主要是*会匹配所有标 ...
- js创建对象的方式 三种
1. 使用直接量创建1个对象: var aobj = { x : 10, y : function(){ console.log("aobj--> "+this.x); } ...
- zendStudio安装Xdebug项目断点调试
1,首先安装xdebug插件 传送门 2,配置php.ini文件如下: [XDebug] xdebug.profiler_append = xdebug.profiler_enable = xdebu ...