2011-05-11 128 views
2

当我在spring bean配置文件中添加一个名称空间时,我能够大幅减少xml配置吗?Spring中的xml配置

例如:

<beans xmlns="http://www.springframework.org/schema/beans" 

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

xmlns:sws="http://www.springframework.org/schema/web-services" 

xsi:schemaLocation="http://www.springframework.org/schema/beans 

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 

http://www.springframework.org/schema/web-services 

http://www.springframework.org/schema/web-services/web-services-2.0.xsd"> 


    <sws:annotation-driven /> 


</beans> 

这个片段让我无法定义PayloadRootAnnotationMethodEndpointMapping明确

回答

3

您指定

<sws:annotation-driven/> 

从文档http://static.springsource.org/spring-ws/site/reference/html/tutorial.html-

通过在我们的配置中使用 元素,我们 可启用@PayloadRoot注释的检测 @PayloadRoot注释。它是 可能(并且相当普遍)在 端点有 多个相关的处理方法,它们中的每一个都处理 不同的XML消息。

这基本上意味着你可以指定你的Java文件中的注释来定义端点 -

@PayloadRoot(namespace = "http://mycompany.com/hr/schemas", localPart = "HolidayRequest") 

因此,你不再需要在XML指定配置。

2

这些是“配置宏”,随着Spring 2.5的推出。他们在宣布豆类的共同安排时,减少了所需的驴工,用宏替换它们。 Spring的例子包括<context:annotation-driven/>

在你的例子中,<sws:annotation-driven/>取代了一堆Spring WS端点映射和处理程序bean,否则你必须明确声明。

请注意,简单地声明XML名称空间本身不会执行任何操作,它是执行此操作的<sws:annotation-driven/>

0

当在配置被检测到

 
<sws:annotation-driven /> 

,框架自动寄存器框架豆以检测端点的映射,以作为消息接收等消息工厂,消息接收器等的回转都是自动注册的。对于更简单的情况,这基本上是一个捷径,我们只需要所有这些bean的默认值。