摘要:
比如我们有下面的一个bean:import java.util.Date; public class Customer { Date date; public Date getDate() { return date; } public void setDate(Date date) { this.date = date; } @Override public String toString() { return "Customer [date=" + date + "]"; } } 注意我们上面的bean中有一个Date,但是如果我们使用下面的配置:& 阅读全文
随笔分类 - spring
Spring中bean配置的继承
2012-12-27 09:50 by Rollen Holt, 6225 阅读, 收藏,
摘要:
In Spring, the inheritance is supported in bean configuration for a bean to share common values, properties or configurations.A child bean or inherited bean can inherit its parent bean configurations, properties and some attributes. In additional, the child beans are allow to override the inherited 阅读全文
Spring中注入List,Set,Map,Properties
2012-12-27 09:44 by Rollen Holt, 54327 阅读, 收藏,
摘要:
下面的例子展示了如何注入List – <list/>Set – <set/>Map – <map/>Properties – <props/>Spring beansimport java.util.List;import java.util.Map;import java.util.Properties;import java.util.Set; public class Customer { private List<Object> lists; private Set<Object> sets; private Ma 阅读全文
Spring中bean的范围
2012-12-27 09:37 by Rollen Holt, 1675 阅读, 收藏,
摘要:
Spring中有5种bean的范围:5 types of bean scopes supported :singleton – Return a single bean instance per Spring IoC container 这个范围也是默认的prototype – Return a new bean instance each time when requestedrequest – Return a single bean instance per HTTP request. *session – Return a single bean instance per HTTP s 阅读全文
Spring中使用inner bean
2012-12-27 09:29 by Rollen Holt, 2228 阅读, 收藏,
摘要:
有点类似java 内部类。看个demo。假设有下面的一个bean:public class Customer { private Person person; public Customer(Person person) { this.person = person; } public void setPerson(Person person) { this.person = person; } @Override public String toString() { return "Customer [person=" + person + "]"; 阅读全文
spring中3中为bean注入值的办法总结
2012-12-27 09:25 by Rollen Holt, 1002 阅读, 收藏,
摘要:
有三种办法,分别是:Normal wayShortcut“p” schema假设我们现在有这么一个bean:public class FileNameGenerator { private String name; private String type; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getType() { return type; } public void setType(String typ... 阅读全文
使用Spring的JavaConfig
2012-12-27 09:16 by Rollen Holt, 8739 阅读, 收藏,
摘要:
之前我们都是在xml文件中定义bean的,比如:<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-3.0.xsd"& 阅读全文
关于使用"/"来 dispatcherServlet 的url-pattern带来的问题
2012-12-26 15:47 by Rollen Holt, 14733 阅读, 收藏,
摘要:
之前一直使用*.do来做的,但是绝的*.do很丑,于是就改用“/”来配置: <servlet> <servlet-name>dispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> < 阅读全文
Spring MVC POST中文乱码解决方案
2012-12-26 13:47 by Rollen Holt, 48063 阅读, 收藏,
摘要:
POST中文乱码解决方案以前,我都是自己编写一个filter,来实现编码,代码如下: 1 public class CharacterEncodingFilter implements Filter { 2 3 private final static Logger log= Logger... 阅读全文
spring MVC中定义异常页面
2012-12-25 17:11 by Rollen Holt, 23005 阅读, 收藏,
摘要:
如果我们在使用Spring MVC的过程中,想自定义异常页面的话,我们可以使用DispatcherServlet来指定异常页面,具体的做法很简单:下面看我曾经的一个项目的spring配置文件: ... 阅读全文
浙公网安备 33010602011771号