Skip to content

Shared DefaultConversionService instance e.g. for BeanPropertyRowMapper [SPR-14948] #19515

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
spring-projects-issues opened this issue Nov 24, 2016 · 4 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Nov 24, 2016

Yanming Zhou opened SPR-14948 and commented

Creating DefaultConversionService instance is not so cheap, it's thread-safe, so we can create a default instance.

class DefaultConversionService{
private static volatile ConversionService defaultConversionService;
public static DefaultConversionService getDefaultInstance(){
if (defaultConversionService == null) {
			synchronized (DefaultConversionService.class) {
				if (defaultConversionService == null) {
					defaultConversionService = new DefaultConversionService();
				}
			}
		}
return defaultConversionService;
}
}

It could be used by other class, for example BeanPropertyRowMapper

//private ConversionService conversionService = new DefaultConversionService();
private ConversionService conversionService = DefaultConversionService.getDefaultInstance();

Affects: 4.3.4

Issue Links:

Referenced from: commits spring-projects/spring-integration@d96b8e0

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Good point, provided that we're lazily initializing it, such a common shared DefaultConversionService makes sense these days, in particular with further use of it in 4.3 here.

So as of 4.3.5, we're reusing such a shared DefaultConversionService instance in BeanPropertyRowMapper, PropertySourcesPropertyResolver, StandardTypeConverter, GenericMessageConverter and also in our common MVC argument resolvers, if no specific ConversionService has been configured otherwise.

@spring-projects-issues
Copy link
Collaborator Author

Tim Lenz commented

My webapp no longer starts up after upgrading from 4.3.3 to 4.3.7. I think it's related to this issue. The stack trace is

Caused by: java.lang.NoSuchMethodError: org.springframework.core.convert.support.DefaultConversionService.getSharedInstance()Lorg/springframework/core/convert/ConversionService;
at org.springframework.jdbc.core.BeanPropertyRowMapper.<init>(BeanPropertyRowMapper.java:91)
at org.springframework.jdbc.core.BeanPropertyRowMapper.newInstance(BeanPropertyRowMapper.java:380)

I have two static BeanPropertyRowMapper instances in my class, created using BeanPropertyRowMapper.newInstance(Class<?> mappedClass)

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Tim Lenz, this is a new method introduced in 4.3.5. Please make sure that you're actually running against spring-core-4.3.7.jar; it looks like there's an old 4.3.3 jar in your classpath still.

@spring-projects-issues
Copy link
Collaborator Author

Tim Lenz commented

Thank you, somehow I had a dependency in my pom.xml that was still forcing 4.3.3 for spring-core. All good now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants