Skip to content
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

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

Closed
spring-projects-issues opened this issue Nov 24, 2016 · 4 comments
Assignees
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues 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:

  • #19034 Ineffective synchronization in StandardTypeConverter constructor
  • #18461 BeanPropertyRowMapper should use ConversionService for date-time support
  • #19556 Update JdbcUtils to improve enum support

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

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 24, 2016

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

@spring-projects-issues spring-projects-issues commented Mar 30, 2017

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

@spring-projects-issues spring-projects-issues commented Mar 30, 2017

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

@spring-projects-issues spring-projects-issues commented Mar 30, 2017

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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.