Import Spring XML files into @Configuration
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
We have a huge spring xml-based project. We would like to change it to spring boot and it is not easy to change everything to @Beans. Just to be begin with, can I keep our old web.xml as it is if I set packaging to war in pom?
Or web.xml should be converted to Config before we can run spring-boot?
FileNotFoundException: Could not open ServletContext resource [classpath:/main/webapp/WEB-INF/spring-servlet.xml]
Tried many path combinations for xml file but didnt work.
Please help.
is there a way to accomlish the same class with Annotations like @Configuration
@Import({ AppConfigWeb.class })
@ImportResource(“classpath:/config/spring.xml”)
using spring2.5.6 ? I know this is available only from spring 3. Please let me know an alternative approach.
If you have a project of spring framework whenever you import file code
hi, I cannot find the Appconfig.java file? where should I create it or find it?
is there a way to import config in the xml file? i have a dependency project that is spring 4 but is being imported into a Spring 3 project which has XML configuration. The problem is i cannot use autowired beans as the parent project is not aware of those beans for autowiring
In Spring XML, just scan the JavaConfig file. Try below links
1. http://docs.spring.io/spring-javaconfig/docs/1.0.0.M4/reference/html/ch06.html
2. https://mkyong.com/spring/spring-mixing-xml-and-javaconfig/