Spring的 @Service 和 @Transactional 注解对 Service 很是有用。建立并使用项目特写的元注解,能够将业务接口从基础架构中抽象出来。 java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
packagecom.gordondickens.service.annotation;
importorg.springframework.stereotype.Service;
importorg.springframework.transaction.annotation.Transactional;
importjava.lang.annotation.ElementType;
importjava.lang.annotation.Retention;
importjava.lang.annotation.RetentionPolicy;
importjava.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Transactional
public
@interface AppService {
String value() default"";
}
|
1
2
3
4
5
|
...
@AppService
publicclassMyClass() {
...
}
|
Spring中 PropertyEditors 专一于应用中的输入和输出的转换。 spring
org.springframework.beans.PropertyEditorRegistrySupport 类显示的内建了 String <–> object 的支持. 在咱们的应用程序中,只需知道怎么使用便可。咱们的应用程序使用XML做为配置,而且设置属性值时,Spring使用反射机制肯定参数的类型,若是属性类型不是一个字符串,Spring将查找内建的 PropertyEditor实现,将字符串转换为目标属性类型。咱们也能够建立自定义的 PropertyEditor实现,并注册该类型。例如:美国社会化安全码和电话号码 Craig Wall’s Spring in Action, 3rd Ed 数组
Spring3.0 引入了一个 ConversionService 接口,该接口提供咱们注册一个将 Object <–> 其余对象的转换服务的能力。 使用转换注册,咱们能注册一个自定义的转换类,自动将一个对象转换为另外一个对象:MyObject <–> MyOtherObject。具体请参看: Using Spring Customer Type Converter Blog. 安全