【发布时间】:2017-07-20 07:32:57
【问题描述】:
我正在使用弹簧引导。并希望从目录加载资源。以下代码适用于文件系统环境。 但是在使用 Jar 时会出现 FileNotFoundException,因为 Spring 尝试访问文件系统路径,但无法访问 JAR 中的路径。
@EnableAutoConfiguration
@Configuration
public class Application implements CommandLineRunner {
@Autowired
private MongoDBMigrator migrator;
@Autowired
private ApplicationContext ctx;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
public void run(String... args) throws Exception {
migrator.runScripts(ctx.getResources("classpath:db/*.js"));
}
}
需要做些什么才能使其也可以与 jar 一起使用
【问题讨论】:
-
你的 jar 在类路径中吗?
-
@rahul singh:是的。它在那里