将Spring XML配置转换为Java配置

dea*_*mon 7 java xml configuration spring

我想使用Spring配置Java,但几乎所有的例子都是用XML编写的,我不知道如何将它们翻译成Java.查看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>
Run Code Online (Sandbox Code Playgroud)

怎么能转换成Java配置?或者,更一般地说,如何将Spring XML配置转换为Java?在Spring参考中有一些关于Java confing的部分,但它没有那么有用.

axt*_*avt 1

您无法使用自定义命名空间(例如http://www.springframework.org/schema/security)转换 XML 配置。但是,您可以将 XML 配置与基于 Java 的配置混合使用@ImportResource