Spring Setter/Getter 注入的对象时的两种形式 和使用 p的命名空间
2016-04-08 00:00
288 查看
摘要: Spring 命名空间的使用 还有就是 Setter/Getter的注入
一些更加简便的方式 来源 http://blog.csdn.net/joker_zhou/article/details/8551692
p:命名空间:
xmlns:p="http://www.springframework.org/schema/p"
作用:简化在xml配置bean的属性 在<bean>中使用p:属性名来配置
AOP:命名空间:
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation:
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
作用:简化AspectJ的AOP在xml中配置
util:命名空间:
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation:
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
context:命名空间:
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation:
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 作用:1.配置自动扫描bean注解类
context:命名空间:
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation:
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
具体配置如下:
java 代码同上。
<?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.xsd"> <bean id="piano" class="com.springinaction.springidol.Piano" scope="prototype" init-method="init" destroy-method="destory"> </bean> <bean id="people" class="com.springinaction.springidol.People"> <property name="name" value="nihao" /> <!-- 第一种注入 方式<property name="piano" ref="piano" /> --> <!-- 内部bean 的注入--> <property name="piano"> <bean class="com.springinaction.springidol.Piano" /> </property> </bean> </beans>
public class People { private String name; private String age; private String area; private Piano piano; public Piano getPiano() { return piano; } public void setPiano(Piano piano) { this.piano = piano; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAge() { return age; } public void setAge(String age) { this.age = age; } public String getArea() { return area; } public void setArea(String area) { this.area = area; } public static void main(String args[]){ ApplicationContext ac=new ClassPathXmlApplicationContext("com/springinaction/springidol/springidol-context-2.xml"); People people=(People)ac.getBean("people"); System.out.println(people.getName()); people.getPiano().play(); } }
一些更加简便的方式 来源 http://blog.csdn.net/joker_zhou/article/details/8551692
p:命名空间:
xmlns:p="http://www.springframework.org/schema/p"
作用:简化在xml配置bean的属性 在<bean>中使用p:属性名来配置
AOP:命名空间:
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation:
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
作用:简化AspectJ的AOP在xml中配置
util:命名空间:
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation:
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
context:命名空间:
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation:
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 作用:1.配置自动扫描bean注解类
context:命名空间:
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation:
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
具体配置如下:
<?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-3.0.xsd"> <bean id="piano" class="com.springinaction.springidol.Piano" scope="prototype" init-method="init" destroy-method="destory"> </bean> <bean id="people" class="com.springinaction.springidol.People" p:name="haha" p:piano-ref="piano" /> </beans>
java 代码同上。
相关文章推荐
- 防御SQL注入攻击时需要注意的一个问题
- Sql2005注入辅助脚本[修改版]
- MySQL注入中导出字段内容的研究通过注入导出WebShell
- 浅析MySQL的注入安全问题
- C++编程中的命名空间基本知识讲解
- sql server注入建立虚拟目录的方法
- PHP中怎样防止SQL注入分析
- C++命名空间实例解析
- php命名空间学习详解
- C#使用带like的sql语句时防sql注入的方法
- js命名空间写法示例
- JavaScript创建命名空间的5种写法
- Javascript学习笔记之函数篇(六) : 作用域与命名空间
- mssql注入躲避IDS的方法
- Spring中属性注入详解
- c# 命名空间和程序集
- 理运用命名空间让js不产生冲突避免全局变量的泛滥
- ASP注入详细命令40条第1/2页
- PHP 5.3新特性命名空间规则解析及高级功能
- Cookie 注入是怎样产生的