利用spring的表达式语言注入bean
来源:互联网 发布:软件学报 期刊ccf 编辑:程序博客网 时间:2024/06/11 09:43
以下是xml版
applicationContext.xml
<bean id="bookBean" class="com.javacodegeeks.snippets.enterprise.Book"><property name="id" value="12345" /><property name="title" value="Le Petit Prince (The Little Prince)" /></bean> <bean id="authorBean" class="com.javacodegeeks.snippets.enterprise.Author"><property name="name" value="Antoine de Saint-Exupéry" /><property name="book" value="#{bookBean}" /><property name="bookTitle" value="#{bookBean.title}" /></bean>
package com.javacodegeeks.snippets.enterprise;import org.springframework.beans.factory.annotation.Value;import org.springframework.stereotype.Component;public class Book {private long id;private String title;public long getId() {return id;}public void setId(long id) {this.id = id;}public String getTitle() {return title;}public void setTitle(String title) {this.title = title;} public String getBookInfo(String authorName){return authorName + " has writen the book " + title + ", with book id " + ""+ id + ".";}@Overridepublic String toString(){return title;}}
package com.javacodegeeks.snippets.enterprise;import org.springframework.beans.factory.annotation.Value;import org.springframework.stereotype.Component;public class Author { private String name;private Book book;private String bookTitle;private String fullAuthorInfo;public String getName() {return name;}public void setName(String name) {this.name = name;}public Book getBook() {return book;}public void setBook(Book book) {this.book = book;}public String getBookTitle() {return bookTitle;}public void setBookTitle(String bookTitle) {this.bookTitle = bookTitle;}public String getFullAuthorInfo() {return fullAuthorInfo;}public void setFullAuthorInfo(String fullAuthorInfo) {this.fullAuthorInfo = fullAuthorInfo;}@Overridepublic String toString(){return name + " has writen the book : " + book + ". \n" + bookTitle + " is a wonderful title of a wonderful book.";}}
package com.javacodegeeks.snippets.enterprise;import org.springframework.context.ConfigurableApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class App {public static void main(String[] args) {ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");Author author = (Author) context.getBean("authorBean");System.out.println(author.toString());System.out.println(author.getFullAuthorInfo());context.close();}}
原文:http://examples.javacodegeeks.com/enterprise-java/spring/beans-spring/spring-expression-language-example/
源代码:http://pan.baidu.com/share/link?shareid=598250216&uk=3878681452
- 利用spring的表达式语言注入bean
- Spring的bean注入
- 【Spring】 Bean的注入
- Spring的bean注入方式
- spring bean注入的方式
- Spring中bean的注入
- 85-002-19 SSH项目中利用spring的SpEL表达式语言来注入文件在项目中绝对路径
- Spring连接数据库的方式1:利用Spring实现bean属性setter方式注入
- web 工程中利用Spring的 ApplicationContextAware接口自动注入bean
- 利用SPring实现bean属性setter方式注入
- Spring Bean 注入 Servlet 的方法
- Spring方法注入非单例bean的调用
- Spring--多种Bean的注入(上)
- Spring--多种Bean的注入(中)
- Spring--多种Bean的注入(下)
- spring 注入bean 时的初始化
- Spring Bean 注入 Servlet 的方法
- spring框架bean注入的时机问题
- CSS-选择器特殊性
- hibernate4.0+版本和3.0区别
- Wince下面添加应用程序,并且自动运行----几种方式介绍
- 调整 Thunderbird 邮件主题和正文的字体、字号,修正中文显示乱码
- 遍历List 同时 remove 元素
- 利用spring的表达式语言注入bean
- 树状数组
- Linux 16进制编辑
- MVC3中viewdata,tempdata,viewbag总结
- Hibernate4 Annotation实例
- 网游服务器通信架构的设计方案
- 递归和非递归的方法往二叉排序树中插入新的节点
- Java中的泛型
- linux集群时间同步