问题描述
我正在尝试创建基于spring的应用程序,但是在构建后,在初始化spring上下文-> No auto configuration classes found in META-INF/spring.factories
时遇到异常.我在应用程序中大量使用spark,因此不得不使用maven-assembly-plugin
打包jar(否则我将无法运行spark作业).
I'm trying to create spring based application but after the build i'm getting exception while initializing the spring context -> No auto configuration classes found in META-INF/spring.factories
.I'm working heavily with spark in my application and i'm forced to use maven-assembly-plugin
to package my jar (otherwise i'm unable to run spark job).
我的主要班级的样本:
@SpringBootApplication
@EnableAutoConfiguration
public class MyMainClass {
public static void main(String[] args) {
ConfigurableApplicationContext ctx = new SpringApplicationBuilder(MyMainClass.class).web(false)
.run(args);
SparkJob job = ctx.getBean(SparkJob.class);
job.prepareJobAndRun();
ctx.close();
}
}
当我添加
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.mypackage.MyMainClass
一切正常,但我不想手动添加它们.是否有机会在没有spring-boot-maven-plugin
的情况下进行这项工作?
everything works as expected, but i don't want to add them manually.Any chance to make this work without the spring-boot-maven-plugin
?
推荐答案
我发现,您可以将自己的META-INF/spring.factories
添加到src/main/resources
.然后将这个自定义的spring.factories包装到jar中.经过测试,可以正常工作.
I was able to found out, that you can add your own META-INF/spring.factories
to src/main/resources
. This custom spring.factories will be then packed to jar. Tested, working.
这篇关于META-INF/spring.factories中缺少spring自动配置类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!