首页 > 解决方案 > 从spring xml中读取

问题描述

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.context.annotation.ImportResource;

@SpringBootApplication
@EnableAutoConfiguration(exclude={file1.class, file2.class})
@ImportResource(locations = {"classpath*:applicationContext.xml"})
public class Trans{

    public static void main(String[] args) {
        SpringApplication.run(Trans.class, args);
    }

}

当 jar 中存在 XML 时,它可以正常工作并读取 XML。我希望将 XML 从 jar 中删除到机器上的现有文件夹中。执行此操作时,不会读取 XML。如何从机器文件系统而不是 jar 中读取 XML?

提前致谢!

标签: javaspringspring-boot

解决方案


尝试这个:

@ImportResource(locations = {"file:/some/resource/path/applicationContext.xml"})

推荐阅读