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

#1368 - respect FactoryBean.getObjectType contract, use context… #1371

Merged
merged 2 commits into from
Aug 18, 2020

Conversation

zyro23
Copy link
Contributor

@zyro23 zyro23 commented Aug 18, 2020

…classloader where appropriate

  • DatastoreServiceMethodInvokingFactoryBean.getObjectType returns null if not initialized (i.e. arguments is null, getArguments() returns Object[]). that allows AbstractAutowireCapableBeanFactory to initialize DatastoreServiceMethodInvokingFactoryBean if necessary

  • AbstractDatastoreInitializer and SoftServiceLoader use the context classloader to load data service classes. this way, autowiring data services by type works reliably with spring boot devtools restart (RestartClassLoader)

@puneetbehl primarily for review by you.

after i fixed DatastoreServiceMethodInvokingFactoryBean.getObjectType locally and ran the sample app, i still got a NoSuchBeanDefinitionException although i could see the bean definition..

after some fun debugging in, i saw that it was again classloader-related: 2 different instances of interface DummyDataService being compared by DefaultListableBeanFactory.findAutowireCandidates/ClassUtils.isAssignable: one by AppClassLoader, the other one by RestartClassLoader.

do you have a suggestion how to properly unit/integration test this? i saw grails/gorm-hibernate5/examples/test-data-service but the tests do not use the restart classloader anyway, right?

thanks for taking a look.

… classloader where appropriate

- DatastoreServiceMethodInvokingFactoryBean.getObjectType returns null if not initialized (i.e. arguments is null, getArguments() returns Object[]). that allows AbstractAutowireCapableBeanFactory to initialize DatastoreServiceMethodInvokingFactoryBean if necessary

- AbstractDatastoreInitializer and SoftServiceLoader use the context classloader to load data service classes. this way, autowiring data services by type works reliably with spring boot devtools restart (RestartClassLoader)
@zyro23
Copy link
Contributor Author

zyro23 commented Aug 18, 2020

fyi: being curious, i tried to revert e8ef560 on top of this commit - and the sample app still starts sucessfully injecting the interface-typed data service with devtools restart enabled.

@@ -22,7 +22,10 @@ class DatastoreServiceMethodInvokingFactoryBean extends MethodInvokingFactoryBea

@Override
Class<?> getObjectType() {
arguments[0] as Class<?>
if (arguments) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the check should be if (arguments != null && arguments.size() == 1 ). Also, instead of returning null maybe we should call super.getObjectType().

@puneetbehl
Copy link
Contributor

Also, it would be great if you could send a PR to include the failing scenario in the sample application. https://github.com/grails/gorm-hibernate5/tree/7.0.x/examples/test-data-service

@zyro23
Copy link
Contributor Author

zyro23 commented Aug 18, 2020

Also, it would be great if you could send a PR to include the failing scenario in the sample application. https://github.com/grails/gorm-hibernate5/tree/7.0.x/examples/test-data-service

unfortunately i found no way to enable devtools restart for one or all integration tests (ref. https://github.com/spring-projects/spring-boot/blob/v2.1.15.RELEASE/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/DefaultRestartInitializer.java) - any ideas?

and i think adding devtools and a TestConfig so that bootRun fails does not help much either..

@puneetbehl
Copy link
Contributor

Right, now that you mentinoed it I realized that I also failed to achieve the same earlier. However, I was thinking of testing that you are able to inject the Data Service into BeanPostProcessor (the sample application you shared).

@zyro23
Copy link
Contributor Author

zyro23 commented Aug 18, 2020

sure thats np! pr asap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants