将Spring XML配置转换为Java配置 [英] Translate Spring XML configuration to Java config
问题描述
我想使用Spring with Java配置,但几乎所有的例子都是用XML编写的,我不知道如何将它们翻译成Java。查看这些来自Spring Security 3的示例:
I'd like to use Spring with Java configuration, but almost all examples are writte in XML and I don't know how to translate them to Java. Look at these examples from Spring Security 3:
<http auto-config='true'>
<intercept-url pattern="/**" access="ROLE_USER" />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="jimi" password="jimispassword" authorities="ROLE_USER, ROLE_ADMIN" />
<user name="bob" password="bobspassword" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
<password-encoder hash="sha">
<salt-source user-property="username"/>
</password-encoder>
如何转换为Java配置?或者,更一般地,我如何将Spring XML配置转换为Java?有一小部分关于 Java confing in the Spring reference ,但它没有帮助。
How could this translated to Java config? Or, more generally, how can I translate Spring XML config to Java? There is a little section about Java confing in the Spring reference but it is not that helpful.
推荐答案
带有自定义命名空间的配置(例如 http://www.springframework.org/schema/security
)。但是,您可以使用 @ImportResource
You can't translate XML configurations with custom namespaces (such as http://www.springframework.org/schema/security
). However, you can mix XML configurations with Java-based using @ImportResource
这篇关于将Spring XML配置转换为Java配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!