@SpringBootApplication @ImportResource
От: purser Россия  
Дата: 06.12.18 08:20
Оценка:
Есть приложение, которое может запускаться в разных 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"})

В чём может быть причина и как побороть?
Re: @SpringBootApplication @ImportResource
От: bzig  
Дата: 06.12.18 14:04
Оценка:
P>В чём может быть причина и как побороть?

Если локально воспроизводится, поставь брекпойнты и посмотри, это ж опенсорц

В 5м Спринге начать стоит отсюда
org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader#loadBeanDefinitionsFromImportedResources
Re: @SpringBootApplication @ImportResource
От: bzig  
Дата: 06.12.18 14:05
Оценка:
P>@ImportResource({"classpath*:beans_*.xml"})
P>@ImportResource({"classpath:beans_prod_pdf_compressor.xml","classpath:beans_prod_zip_compressor.xml", "classpath:beans_prod_images_compressor.xml", "classpath:beans_prod.xml"})

И навскидку — у тебе в первом случае "classpath*:"
Re: @SpringBootApplication @ImportResource
От: GarryIV  
Дата: 06.12.18 15:40
Оценка: 4 (1)
Здравствуйте, 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.


Вобщем тут все зависи от веблоджиковского класслоадера.
Я бы сто раз подумал а надо ли оно мне такое счастье.
WBR, Igor Evgrafov
Re[2]: @SpringBootApplication @ImportResource
От: bzig  
Дата: 06.12.18 16:03
Оценка:
О, а я и не знал про "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 ) или по одному указывать
Отредактировано 06.12.2018 16:06 мамут ушёл, и я пойду . Предыдущая версия . Еще …
Отредактировано 06.12.2018 16:04 мамут ушёл, и я пойду . Предыдущая версия .
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.