Есть приложение, которое может запускаться в разных AS и standalone
@SpringBootApplication
@Configuration
@ImportResource({"classpath*:beans_*.xml"})
public class MyApplication extends SpringBootServletInitializer implements WebApplicationInitializer {
public static void main(String[] args) {
SpringApplication.run(MyApplication .class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MyApplication.class);
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
servletContext.addListener(IIOProviderContextListener.class);
super.onStartup(servletContext);
}
}
Проблема, которая возникает только только при деплое в WebLogic —
не загружаются файлы с описанием бинов, которые указаны в
@ImportResource({"classpath*:beans_*.xml"})
Но работает, если их явно перечислить
@ImportResource({"classpath:beans_prod_pdf_compressor.xml","classpath:beans_prod_zip_compressor.xml", "classpath:beans_prod_images_compressor.xml", "classpath:beans_prod.xml"})
В чём может быть причина и как побороть?
P>В чём может быть причина и как побороть?
Если локально воспроизводится, поставь брекпойнты и посмотри, это ж опенсорц
В 5м Спринге начать стоит отсюда
org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader#loadBeanDefinitionsFromImportedResources
Здравствуйте, purser, Вы писали:
P>В чём может быть причина и как побороть?
The wildcard classpath relies on the getResources() method of the underlying classloader. As most application servers nowadays supply their own classloader implementation, the behavior might differ, especially when dealing with jar files. A simple test to check if classpath* works is to use the classloader to load a file from within a jar on the classpath: getClass().getClassLoader().getResources("<someFileInsideTheJar>"). Try this test with files that have the same name but are placed inside two different locations. In case an inappropriate result is returned, check the application server documentation for settings that might affect the classloader behavior.
Вобщем тут все зависи от веблоджиковского класслоадера.
Я бы сто раз подумал а надо ли оно мне такое счастье.
О, а я и не знал про "classpath*"
Его проблема там явно описана
Other notes relating to wildcards
Please note that classpath*: when combined with Ant-style patterns will only work reliably with at least one root directory before the pattern starts, unless the actual target files reside in the file system. This means that a pattern like classpath*:*.xml might not retrieve files from the root of jar files but rather only from the root of expanded directories.
У него нет корневой директории, к которой можно привязаться и начать сканирование. Надо перемещать файлы в подпапку типа "conf" (
classpath*:conf/beans_*.xml ) или по одному указывать