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

Multiple PropertySourcesPlaceholderConfigurers do not work with placeholder defaults [SPR-10240] #14873

Closed
spring-issuemaster opened this Issue Jan 29, 2013 · 4 comments

Comments

Projects
None yet
1 participant
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster commented Jan 29, 2013

Paul Tomlin opened SPR-10240 and commented

While issue #14356 discusses this with respect to PropertyPlaceholderConfigurer, this issue specifically deals with the PropertySourcesPlaceholderConfigurer. I feel there is sufficient difference in their intended usage to warrant another ticket.

A PSPC will register the source with the environment, from which it may later be used by any number of locations requiring property lookup.

The problem is that the current implementation also processes the bean factory for every instance of PSPC that is configured. Like #14356, this causes placeholders which are not matched by the current environment to be replaced with their defaults, before later PSPCs have had a chance to load and populate the environment.

In this scenario @ignore-unresolvable doesn't help.

The issue really is that there's no way to register a property source, from within XML, without also having all placeholders processed.

There are multiple potential fixes for this, but I'm trying to illustrate there is a real problem.

The below test fails on bean2 because value == "Borked"

module1.greeting=Hello World
module2.greeting=Hello Universe
<context:property-placeholder location="module1.properties"/>

<bean id="bean1" class="PSPCTest$Holder">
  <property name="value" value="${module1.greeting:Borked}"/>
</bean>
<context:property-placeholder location="module2.properties"/>

<bean id="bean2" class="PSPCTest$Holder">
  <property name="value" value="${module2.greeting:Borked}"/>
</bean>
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({
	"classpath:/module1.xml",
	"classpath:/module2.xml"
})
public class PSPCTest {

	@Autowired
	@Qualifier("bean1")
	private Holder bean1;

	@Autowired
	@Qualifier("bean2")
	private Holder bean2;

	@Test
	public void testBean1Value() {
		assertEquals("Hello World", bean1.getValue());
	}
	@Test
	public void testBean2Value() {
		assertEquals("Hello Universe", bean2.getValue());
	}

	public static class Holder {
		private String value;
		public void setValue(String value) {
			this.value = value;
		}
		public String getValue() {
			return value;
		}
	}
}


Affects: 3.1.4, 3.2.1

Issue Links:

  • #14623 Using multiple PropertyPlaceholderConfigurer breaks @Value default value behavior ("duplicates")
@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Jan 29, 2013

Paul Tomlin commented

Looks like this may duplicate issue #14623

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Jan 30, 2013

Phil Webb commented

Thanks Paul, it does look like this is a duplicate so I will close this issue. Unfortunately there is not an immediately obvious fix for this so you may want to consider some of the workarounds discussed in #14623

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Jan 30, 2013

Paul Tomlin commented

Thanks Phil, I've made up a local workaround which involves using a separate namespace and a PropertySource registration mechanism.

<environment:property-source location="..."/>

The handler simply creates an EnvironmentAware BeanFactoryPostProcessor, which registers the resulting PropertySource with the environment. Seems to work sufficiently for my needs, I'll throw a Github project up when I have a chance.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Jan 31, 2013

Phil Webb commented

Hi Paul,

I see that you recently added a link to your GitHub project on #14623. Thanks! I am sure it will help a lot of people.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment