﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-seasun-随笔分类-1.01 spring</title><link>http://www.blogjava.net/shiwenfeng/category/42358.html</link><description>在不断模仿、思考、总结中一步一步进步！</description><language>zh-cn</language><lastBuildDate>Mon, 25 Jan 2010 11:23:12 GMT</lastBuildDate><pubDate>Mon, 25 Jan 2010 11:23:12 GMT</pubDate><ttl>60</ttl><item><title>Spring3.0带来的新特性</title><link>http://www.blogjava.net/shiwenfeng/archive/2010/01/25/310750.html</link><dc:creator>shiwf</dc:creator><author>shiwf</author><pubDate>Mon, 25 Jan 2010 09:26:00 GMT</pubDate><guid>http://www.blogjava.net/shiwenfeng/archive/2010/01/25/310750.html</guid><wfw:comment>http://www.blogjava.net/shiwenfeng/comments/310750.html</wfw:comment><comments>http://www.blogjava.net/shiwenfeng/archive/2010/01/25/310750.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/shiwenfeng/comments/commentRss/310750.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/shiwenfeng/services/trackbacks/310750.html</trackback:ping><description><![CDATA[<p><font style="background-color: #cce8cf">一、首先，模块的组织更加的细致，从那么多的jar分包就看的出来：</font></p>
<p><font style="background-color: #cce8cf">&nbsp;</font></p>
<p><font style="background-color: #cce8cf">Spring的构建系统以及依赖管理使用的是Apache Ivy，从源码包看出，也使用了Maven。</font></p>
<p><font style="background-color: #cce8cf">Maven确实是个好东西，好处不再多言，以后希望能进一步用好它。</font></p>
<p><font style="background-color: #cce8cf">二、新特性如下：</font></p>
<p><font style="background-color: #cce8cf">Spring Expression Language （Spring表达式语言）</font></p>
<p><font style="background-color: #cce8cf">IoC enhancements/Java based bean metadata （Ioc增强/基于Java的bean元数据）</font></p>
<p><font style="background-color: #cce8cf">General-purpose type conversion system and UI field formatting system （通用类型转换系统和UI字段格式化系统）</font></p>
<p><font style="background-color: #cce8cf">Object to XML mapping functionality (OXM) moved from Spring Web Services project （对象到XML映射功能从Spring Web Services项目移出）</font></p>
<p><font style="background-color: #cce8cf">Comprehensive REST support （广泛的REST支持）</font></p>
<p><font style="background-color: #cce8cf">@MVC additions （@MVC增强）</font></p>
<p><font style="background-color: #cce8cf">Declarative model validation （声明式模型验证）</font></p>
<p><font style="background-color: #cce8cf">Early support for Java EE 6 （提前对Java EE6提供支持）</font></p>
<p><font style="background-color: #cce8cf">Embedded database support （嵌入式数据库的支持）</font></p>
<p><font style="background-color: #cce8cf">三、针对Java 5的核心API升级</font></p>
<p><font style="background-color: #cce8cf">1、BeanFactory接口尽可能返回明确的bean实例，例如：</font></p>
<p><font style="background-color: #cce8cf">T getBean(String name, Class requiredType)</font></p>
<p><font style="background-color: #cce8cf">Map getBeansOfType(Class type)</font></p>
<p><font style="background-color: #cce8cf">Spring3对泛型的支持，又进了一步。个人建议泛型应该多用，有百利而无一害！</font></p>
<p><font style="background-color: #cce8cf">2、Spring的TaskExecutor接口现在继承自java.util.concurrent.Executor：</font></p>
<p><font style="background-color: #cce8cf">扩展的子接口AsyncTaskExecutor支持标准的具有返回结果Futures的Callables。</font></p>
<p><font style="background-color: #cce8cf">任务计划，个人还是更喜欢Quartz。</font></p>
<p><font style="background-color: #cce8cf">3、新的基于Java5的API和SPI转换器</font></p>
<p><font style="background-color: #cce8cf">无状态的ConversionService 和 Converters</font></p>
<p><font style="background-color: #cce8cf">取代标准的JDK PropertyEditors</font></p>
<p><font style="background-color: #cce8cf">类型化的ApplicationListener，这是一个实现&#8220;观察者设计模式&#8221;使用的事件监听器。</font></p>
<p><font style="background-color: #cce8cf">基于事件的编程模式，好处多多，在项目中应该考虑使用，基于事件、状态迁移的设计思路，有助于理清软件流程，和减少项目的耦合度。</font></p>
<p><font style="background-color: #cce8cf">四、Spring表达式语言</font></p>
<p><font style="background-color: #cce8cf">Spring表达式语言是一种从语法上和统一表达式语言（Unified EL）相类似的语言，但提供更多的重要功能。它可以在基于XML配置文件和基于注解的bean配置中使用，并作为基础为跨Spring portfolio平台使用表达式语言提供支持。</font></p>
<p><font style="background-color: #cce8cf">接下来，是一个表达式语言如何用于配置一个数据库安装中的属性的示例：</font></p>
<p><font style="background-color: #cce8cf">&lt;bean class="mycompany.RewardsTestDatabase"&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;property name="databaseName"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; value="#{systemProperties.databaseName}"/&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;property name="keyGenerator"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; value="#{strategyBean.databaseKeyGenerator}"/&gt;<br />
&lt;/bean&gt;<br />
如果你更愿意使用注解来配置你的组件，那么这种功能同样可用：</font></p>
<p><font style="background-color: #cce8cf">@Repository public class RewardsTestDatabase { <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Value("#{systemProperties.databaseName}") <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void setDatabaseName(String dbName) { &#8230; } <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Value("#{strategyBean.databaseKeyGenerator}") <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public voidsetKeyGenerator(KeyGenerator kg) { &#8230; } <br />
}</font></p>
<p><font style="background-color: #cce8cf">又多一种表达式语言，造轮子的运动还在继续中！</font></p>
<p><font style="background-color: #cce8cf">五、基于Java的bean元数据</font></p>
<p><font style="background-color: #cce8cf">JavaConfig项目中的一些核心特性已经集成到了Spring中来，这意味着如下这些特性现在已经可用了：</font></p>
<p><font style="background-color: #cce8cf">@Configuration </font></p>
<p><font style="background-color: #cce8cf">@Bean </font></p>
<p><font style="background-color: #cce8cf">@DependsOn </font></p>
<p><font style="background-color: #cce8cf">@Primary </font></p>
<p><font style="background-color: #cce8cf">@Lazy </font></p>
<p><font style="background-color: #cce8cf">@Import </font></p>
<p><font style="background-color: #cce8cf">@Value</font></p>
<p><font style="background-color: #cce8cf">又来一堆的注解，无语了，感觉还是配置文件方便！：（</font></p>
<p><font style="background-color: #cce8cf">这儿有一个例子，关于一个Java类如何使用新的JavaConfig特性提供基础的配置信息：</font></p>
<p><font style="background-color: #cce8cf">package org.example.config;</font></p>
<p><font style="background-color: #cce8cf">@Configuration<br />
public class AppConfig {<br />
&nbsp;&nbsp;&nbsp; private @Value("#{jdbcProperties.url}") String jdbcUrl;<br />
&nbsp;&nbsp;&nbsp; private @Value("#{jdbcProperties.username}") String username;<br />
&nbsp;&nbsp;&nbsp; private @Value("#{jdbcProperties.password}") String password;</font></p>
<p><font style="background-color: #cce8cf">&nbsp;&nbsp;&nbsp; @Bean<br />
&nbsp;&nbsp;&nbsp; public FooService fooService() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new FooServiceImpl(fooRepository());<br />
&nbsp;&nbsp;&nbsp; }</font></p>
<p><font style="background-color: #cce8cf">&nbsp;&nbsp;&nbsp; @Bean<br />
&nbsp;&nbsp;&nbsp; public FooRepository fooRepository() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new HibernateFooRepository(sessionFactory());<br />
&nbsp;&nbsp;&nbsp; }</font></p>
<p><font style="background-color: #cce8cf">&nbsp;&nbsp;&nbsp; @Bean<br />
&nbsp;&nbsp;&nbsp; public SessionFactory sessionFactory() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // wire up a session factory<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AnnotationSessionFactoryBean asFactoryBean = <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new AnnotationSessionFactoryBean();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; asFactoryBean.setDataSource(dataSource());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // additional config<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return asFactoryBean.getObject();<br />
&nbsp;&nbsp;&nbsp; }</font></p>
<p><font style="background-color: #cce8cf">&nbsp;&nbsp;&nbsp; @Bean<br />
&nbsp;&nbsp;&nbsp; public DataSource dataSource() { <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new DriverManagerDataSource(jdbcUrl, username, password);<br />
&nbsp;&nbsp;&nbsp; }<br />
}为了让这段代码开始生效，我们需要添加如下组件扫描入口到最小化的应用程序上下文配置文件中：</font></p>
<p><font style="background-color: #cce8cf">&lt;context:component-scan base-package="org.example.config"/&gt;<br />
&lt;util:properties id="jdbcProperties" location="classpath:org/example/config/jdbc.properties"/&gt;</font></p>
<p><font style="background-color: #cce8cf">六、在组件中定义bean的元数据</font></p>
<p><font style="background-color: #cce8cf">感觉Spring提供了越来越多的注解、元数据，复杂性已经超出了当初带来的方便本身！</font></p>
<p><font style="background-color: #cce8cf">七、通用类型转换系统和UI字段格式化系统</font></p>
<p><font style="background-color: #cce8cf">Spring3加入了一个通用的类型转换系统，目前它被SpEL用作类型转换，并且可能被一个Spring容器使用，用于当绑定bean的属性值的时候进行类型转换。</font></p>
<p><font style="background-color: #cce8cf">另外，还增加了一个UI字段格式化系统，它提供了更简单的使用并且更强大的功能以替代UI环境下的JavaBean的PropertyEditors，例如在SpringMVC中。</font></p>
<p><font style="background-color: #cce8cf">这个特性要好好研究下，通用类型转换系统如果果如所言的话，带来的好处还是很多的。</font></p>
<p><font style="background-color: #cce8cf">八、数据层</font></p>
<p><font style="background-color: #cce8cf">对象到XML的映射功能已经从Spring Web Services项目移到了Spring框架核心中。它位于org.springframework.oxm包中。</font></p>
<p><font style="background-color: #cce8cf">OXM?研究下！时间真不够！</font></p>
<p><font style="background-color: #cce8cf">九、Web层</font></p>
<p><font style="background-color: #cce8cf">在Web层最激动人心的新特性莫过于新增的对构件REST风格的web服务和web应用的支持！另外，还新增加了一些任何web应用都可以使用的新的注解。</font></p>
<p><font style="background-color: #cce8cf">服务端对于REST风格的支持，是通过扩展既有的注解驱动的MVC web框架实现的。</font></p>
<p><font style="background-color: #cce8cf">客户端的支持则是RestTemplate类提供的。</font></p>
<p><font style="background-color: #cce8cf">无论服务端还是客户端REST功能，都是使用HttpConverter来简化对HTTP请求和应答过程中的对象到表现层的转换过程。</font></p>
<p><font style="background-color: #cce8cf">MarshallingHttpMessageConverter使用了上面提到的&#8220;对象到XML的映射机制&#8221;。</font></p>
<p><font style="background-color: #cce8cf">十、@MVC增强</font></p>
<p><font style="background-color: #cce8cf">新增了诸如@CookieValue 和 @RequestHeaders这样的注解等。</font></p>
<p><font style="background-color: #cce8cf">十一、声明式模型验证</font></p>
<p><font style="background-color: #cce8cf">支持JSR 303，使用Hibernate Validator作为实现。</font></p>
<p><font style="background-color: #cce8cf">十二、提前对Java EE6提供支持</font></p>
<p><font style="background-color: #cce8cf">提供了使用@Async注解对于异步方法调用的支持（或者EJB 3.1里的 @Asynchronous）</font></p>
<p><font style="background-color: #cce8cf">另外，新增对JSR 303, JSF 2.0, JPA 2.0等的支持。</font></p>
<p><font style="background-color: #cce8cf">十三、嵌入式数据库的支持</font></p>
<p><font style="background-color: #cce8cf">对于嵌入式的Java数据库引擎提供了广泛而方便的支持，诸如HSQL, H2, 以及Derby等。</font></p>
<p><font style="background-color: #cce8cf">这是不是代表一种潮流呢？数据库向越来越小型化发展，甚至小型化到嵌入式了，我认为这在桌面级应用上还是很有市场的。</font></p>
<p><font style="background-color: #cce8cf"></font>&nbsp;</p>
<p><font style="background-color: #cce8cf">本文来自CSDN博客，转载请标明出处：http://blog.csdn.net/abigfrog/archive/2009/10/30/4748685.aspx</font></p>
<img src ="http://www.blogjava.net/shiwenfeng/aggbug/310750.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/shiwenfeng/" target="_blank">shiwf</a> 2010-01-25 17:26 <a href="http://www.blogjava.net/shiwenfeng/archive/2010/01/25/310750.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>