Skip to content

RedisHttpSessionConfiguration breaks application due to PropertyPlaceholderConfigurer #867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mrusinak opened this issue Sep 7, 2017 · 11 comments
Assignees
Labels
for: stack-overflow A question that's better suited to stackoverflow.com

Comments

@mrusinak
Copy link

mrusinak commented Sep 7, 2017

Using Spring Session 1.3.1

RedisHttpSessionConfiguration defines a default PropertyPlaceholderConfigurer - this can cause an application to fail to initialize if the app defines it's own PropertyPlaceholderConfigurer that looks for properties in non-standard locations.

For example, consider a custom configurer that looks in two non-standard locations (one for defaults bundled with the app, another to allow for overrides):

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan/>

    <bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
        <property name="ignoreResourceNotFound" value="true" />
        <property name="locations">
            <list>
                <value>classpath:spring/defaults.properties</value>
                <value>file:${catalina.base}/conf/overrides.properties</value>
            </list>
        </property>
        <property name="ignoreUnresolvablePlaceholders" value="true"/>
    </bean>

</beans>

And a dumb configuration object that uses @Value:

@Component
public class AppProperties {
    @Value( "${value1}" )
    private String value1;

    @Value( "${value2}" )
    private String value2;

    public String getValue1() {
        return value1;
    }

    public String getValue2() {
        return value2;
    }
}

(And of course, with a /spring/defaults.properties under src/main/resources, with value1 and value2 set)

Once <bean class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration"/> is added as a bean, the app fails to initialize with being unable to resolve the values for AppProperties, as the PropertyPlaceholderConfigurer from RedisHttpSessionConfiguration gets tried and dies resolving them.

@vpavic vpavic self-assigned this Sep 8, 2017
@vpavic vpavic added the for: stack-overflow A question that's better suited to stackoverflow.com label Sep 8, 2017
@vpavic
Copy link
Contributor

vpavic commented Sep 8, 2017

This seems to be the same problem as in #775.

Can you attempt to override the PropertySourcesPlaceholderConfigurer provided by Spring Session configuration by assigning the propertySourcesPlaceholderConfigurer id to your PropertySourcesPlaceholderConfigurer bean?

@vpavic vpavic added the status: waiting-for-feedback We need additional information before we can continue label Sep 8, 2017
@mrusinak
Copy link
Author

mrusinak commented Sep 8, 2017

Changing the app's configurer definition to <bean id="propertySourcesPlaceholderConfigurer" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer"> unfortunately still causes the error

@vpavic
Copy link
Contributor

vpavic commented Sep 8, 2017

Thanks for the quick feedback @mrusinak - I'll take a closer look at this.

@vpavic vpavic removed the status: waiting-for-feedback We need additional information before we can continue label Sep 8, 2017
@mrusinak
Copy link
Author

mrusinak commented Sep 8, 2017

I apologize, I was incorrect in my previous statement. Setting the ID does allow the application to start properly (didn't notice earlier that my test hadn't actually used the updated spring context).

Sorry about that!

@vpavic
Copy link
Contributor

vpavic commented Sep 8, 2017

Thanks for the update. So I guess this works around the original problem then?

@mrusinak
Copy link
Author

mrusinak commented Sep 8, 2017

It does. Thanks!

@viraj071
Copy link

@vpavic Any suggestions to get around this problem if you already have multiple PropertySourcesPlaceholderConfigurer beans with each having 'ignoreUnresolvablePlaceholders' field set to true and a unique id. (Its a legacy app) ?

@vpavic
Copy link
Contributor

vpavic commented Sep 17, 2017

@viraj071 Assuming you cannot change the id of any of your existing PropertySourcesPlaceholderConfigurer beans, you could still use essentially the same approach as described in previous comments - declare another PropertySourcesPlaceholderConfigurer bean, name it propertySourcesPlaceholderConfigurer and set the ignoreUnresolvablePlaceholders to true. That bean definition will override the one provided by Spring Session configuration.

Does that work for you?

@vpavic
Copy link
Contributor

vpavic commented Oct 30, 2017

@mrusinak @viraj071 We've made some changes to Redis configuration support that eliminated the need for having PropertySourcesPlaceholderConfigurer bean registered - see #910.

@hhfdna
Copy link

hhfdna commented Sep 28, 2020

we are stuck by this issue. in our project, we dont allow duplicated bean definitions. we turn allow-bean-definition-overriden to false,
so how to fix it? thx

@hhfdna
Copy link

hhfdna commented Sep 28, 2020

thanks@vpavic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: stack-overflow A question that's better suited to stackoverflow.com
Projects
None yet
Development

No branches or pull requests

4 participants