Import Spring XML files into @Configuration
By:Roy.LiuLast updated:2019-08-17
This is common to mix XML configuration into Spring @Configuration, because developers are used to the XML namespaces. In Spring, you can use @ImportResource to import Spring XML configuration files into @Configuration :
AppConfig.java
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportResource; @Configuration @ImportResource("classpath:/config/spring.xml") public class AppConfig {
Another example
AppConfig.java
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportResource; import org.springframework.context.annotation.Import; @Configuration @Import({ AppConfigWeb.class }) @ImportResource("classpath:/config/spring.xml") public class AppConfig {
P.S @ImportResource has been available since Spring 3.0
From:一号门
Previous:Spring Profiles example
COMMENTS