Почему конструктор Bean выполняется 2 раза?

Есть бин, который задается через xml

<bean id="bean" class="somepackage.Someclass">
    <constructor-arg ref="logger" />
</bean>

Есть имплементация ApplicationContextInitializer, чтобы подгрузить необходимые property

    @Override
    public void initialize(@NonNull ConfigurableWebApplicationContext applicationContext) {
        PropertiesPropertySource ps = new PropertiesPropertySource("main", getApplicationProperties(applicationContext));
        applicationContext.getEnvironment().getPropertySources().addFirst(ps);
    }

    private Properties getApplicationProperties(ConfigurableWebApplicationContext applicationContext) {
        PropertiesFactoryBean factoryBean = new PropertiesFactoryBean();
        String appHomeDir = applicationContext.getEnvironment().getProperty(EnvironmentVariables.MY_ENVIRONMENT);
        Resource[] locations = {
                new ClassPathResource(Paths.PROPERTIES_FILE_NAME),
                new PathResource(appHomeDir + "/" + Paths.PROPERTIES_FOLDER + "/" + Paths.PROPERTIES_FILE_NAME),
        };
        factoryBean.setLocations(locations);
        factoryBean.setIgnoreResourceNotFound(true);
        try {
            factoryBean.afterPropertiesSet();
            return factoryBean.getObject();
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }

Ну и соответственно в web.xml

<context-param>
    <param-name>contextInitializerClasses</param-name>
    <param-value>ru.rubezh.firesec.nt.AppContextInitializer</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

Почему конструктор класса Someclass отрабатывает 2 раза?


Ответы (0 шт):