从Spring XML读取

huangapple go评论58阅读模式
英文:

read from 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);
    }

}

当 XML 文件存在于 JAR 包中时,它可以正常工作并被读取。我希望将 XML 文件从 JAR 包中移动到机器上的现有文件夹中。但在这么做时,XML 文件无法被读取。如何从机器文件系统中读取 XML 文件而不是从 JAR 包中读取呢?

提前感谢您的回答!

英文:
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);
	}

}

When the XML exist in the jar its working properly and the XML is read. I wish to remove the XML from the jar to an existing folder on the machine.
When doing it, the XML is not read. How can I read the XML from the machine file system and not from the jar?

Thanks in advance!

答案1

得分: 0

试试这个

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

Try this:

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

huangapple
  • 本文由 发表于 2020年10月21日 03:27:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/64452077.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定