jhipster / jhipster-loaded

DEPRECATED - Java Agent used by JHipster to hot-reload Java classes
http://jhipster.github.io/
51 stars 9 forks source link

Error when reloading service which is registered for interface #23

Open YuriMalinov opened 10 years ago

YuriMalinov commented 10 years ago

When reloading UserDetailsService (for example) I get next error:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [ru.smarty.inpage_help.security.UserDetailsService] is defined
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:319) ~[spring-beans-4.0.7.RELEASE.jar:4.0.7.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:987) ~[spring-context-4.0.7.RELEASE.jar:4.0.7.RELEASE]
    at io.github.jhipster.loaded.reloader.SpringReloader.start(SpringReloader.java:162) [core-0.12.jar:na]
    at io.github.jhipster.loaded.reloader.SpringReloader.reload(SpringReloader.java:106) [core-0.12.jar:na]
    at io.github.jhipster.loaded.JHipsterReloaderThread.batchReload(JHipsterReloaderThread.java:206) [core-0.12.jar:na]
    at io.github.jhipster.loaded.JHipsterReloaderThread.run(JHipsterReloaderThread.java:153) [core-0.12.jar:na]
    at java.lang.Thread.run(Thread.java:724) [na:1.7.0_40]

Some debugging has shown that in SpringReloader:162 //4) Resolve dependencies for existing beans for (Class clazz : existingSpringBeans) { Object beanInstance = applicationContext.getBean(clazz);

Only real class is queried.

But in my case this method throws Exception for my class (ru.smarty.inpage_help.security.UserDetailsService) and returns JdkProxy for class in case of (org.springframework.security.core.userdetails.UserDetailsService).

Unfortunately I don't have enough expertise in Spring internals to make fix myself. Maybe this place should also search for interfaces, implemented by clazz, make list of target Class-es (i.e. class itself, its parents and all implemented interfaces) and then make process for all of them, ignoring errors and giving warning if no target was successfully found?

Right now it gives infinite loop, because beans not cleared and it's repeated again and again.

It should be reproduced on clean jhipster project.

BhawaniSingh commented 10 years ago

@YuriMalinov can you post code of that class.

YuriMalinov commented 10 years ago

This is archive with project to reproduce bug: https://www.dropbox.com/s/07uya0pya5vjorv/loaded-bug.distiled.tgz?dl=0

Steps I do:

  1. mvn compile
  2. bower install
  3. Open in IDEA
  4. Run Application.java with VM Options -javaagent:spring_loaded/springloaded-jhipster.jar -noverify -Dspringloaded=plugins=io.github.jhipster.loaded.instrument.JHipsterLoadtimeInstrumentationPlugin
  5. Open ru.smarty.loaded_bug.security.UserDetailsService
  6. Place space anywhere to change source.
  7. Compile.
  8. Here it is.