我在哪里将我的XML bean放在Spring Boot应用程序中?

Dav*_*omb 27 java xml spring configuration-files spring-boot

我要回到Spring(目前是第4版).现在用它@SpringBootApplication和其他注释都很精彩,但所有文档似乎都忘了提到我如何在XML中定义其他bean!

例如,我想创建一个"SFTP Session Factory",如下所示:http: //docs.spring.io/spring-integration/reference/html/sftp.html

有一些很好的XML来定义bean,但我在哪里放置它以及如何将其链接?以前我做了一个:

ApplicationContext context = new ClassPathXmlApplicationContext(
                "classpath:applicationContext.xml");
Run Code Online (Sandbox Code Playgroud)

指定文件名和位置,但现在我正在尝试使用:

ApplicationContext ctx = SpringApplication.run(Application.class);
Run Code Online (Sandbox Code Playgroud)

我在哪里放置XML文件?是否有一个神奇的春天名称来称呼它?

bvu*_*laj 38

只要您从一个基@Configuration类开始,它可能听起来就像您一样@SpringBootApplication,您也可以使用@ImportResource注释来包含XML配置文件.

@SpringBootApplication
@ImportResource("classpath:spring-sftp-config.xml")
public class SpringConfiguration {
  //
}
Run Code Online (Sandbox Code Playgroud)