Java 在弹簧靴中装入外部震击器
我有一个包含此类的jar文件:Java 在弹簧靴中装入外部震击器,java,spring-boot,Java,Spring Boot,我有一个包含此类的jar文件: @Configuration public class ExternalConfiguration { @Bean(name = "tab") public Tab getTab() { return new Tab(); } } 我的Spring boot应用程序如下所示: @EnableAutoConfiguration @PropertySource("classpath:application.properties") @Compo
@Configuration
public class ExternalConfiguration {
@Bean(name = "tab")
public Tab getTab() {
return new Tab();
}
}
我的Spring boot应用程序如下所示:
@EnableAutoConfiguration
@PropertySource("classpath:application.properties")
@ComponentScan("com.xxx")
public class Application implements CommandLineRunner {
@Autowired
private ApplicationContext context;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
public void run(String... arg0) throws Exception {
Object o1 = context.getBean("tab");
}
}
loader.path=/opt/lib
loader.path=/opt/lib/
loader.path=/opt/lib/external.jar
我在跑步时得到以下信息:
A component required a bean named 'tab' that could not be found.
我已经尝试了loader.path的所有组合,我可以这样想:
@EnableAutoConfiguration
@PropertySource("classpath:application.properties")
@ComponentScan("com.xxx")
public class Application implements CommandLineRunner {
@Autowired
private ApplicationContext context;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
public void run(String... arg0) throws Exception {
Object o1 = context.getBean("tab");
}
}
loader.path=/opt/lib
loader.path=/opt/lib/
loader.path=/opt/lib/external.jar
我将它们放在application.properties中,并在loader.properties中进行了尝试。
我还可以确认ExternalConfiguration的包属于com.xxx——所以应该扫描它以查找组件,对吗
我做错了什么?我如何加载一个外部罐子,让Spring像正常一样加载它。我不想将其添加到pom.xml中。编辑当我把它添加到我的pom中时,它会按预期工作 我真正想要的是告诉Spring“加载此目录中的所有内容”
有什么想法吗?loader.properties在标准/src/main/resources中。我没有回家。我可以确认loader.properties在jar文件的/BOOT-INF/classes目录中。我刚刚做了一个“find/-name loader.properties”,唯一的一个是针对这个项目的。查看一下日志文件<代码>属性启动器正在记录位置和属性。