Announcement Announcement Module
No announcement yet.
Custom authentication provider can't be instantiated Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom authentication provider can't be instantiated

    I'm building my own web application based on the Greenhouse as a great sample.
    The only differences are:
    1. I use XML for application configuration
    2. And I split separate part of the projects (persistence, services, social) into the separate modules/sub-projects.

    I've spent 2 days trying to figure out where is the difference between my application and the Greenhouse (Greenhouse runs fine from my IDE, and everything works as expected).
    The problem I have - container is not able to instantiate custom usernamePasswordAuthenticationProvider.
    There is the error:
    Could not instantiate bean class [com.myappl.service.UsernamePasswordAuthenticationP rovider]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.myappl.service.UsernamePasswordAuthenticationP rovider.<init>()
    at nitionValueResolver.resolveReference(BeanDefinitio
    at nitionValueResolver.resolveValueIfNecessary(BeanDe
    at torResolver.resolveConstructorArguments(Constructo
    at torResolver.autowireConstructor(ConstructorResolve
    at AutowireCapableBeanFactory.autowireConstructor(Abs
    at AutowireCapableBeanFactory.createBeanInstance(Abst
    at AutowireCapableBeanFactory.doCreateBean(AbstractAu
    at AutowireCapableBeanFactory.createBean(AbstractAuto
    at BeanFactory$1.getObject( 94)
    at ingletonBeanRegistry.getSingleton(DefaultSingleton
    at BeanFactory.doGetBean( )
    at BeanFactory.getBean(
    at DebugBeanFactoryPostProcessor.postProcessBeanFacto ry(
    at ationContext.invokeBeanFactoryPostProcessors(Abstr
    at ationContext.invokeBeanFactoryPostProcessors(Abstr
    at ationContext.refresh(AbstractApplicationContext.ja va:446)
    at org.springframework.web.context.ContextLoader.conf igureAndRefreshWebApplicationContext(ContextLoader .java:384)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(
    at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.
    I tried all imaginary possible ways to fix it. The reason for this, that I @Inject AuthenticationService through constructor injection for UsernamePasswordAuthenticationProvider, which is declared as @Service. Everything is very similar to the Greenhouse application, so it makes me crazy. Why do I need default no arg constructor? I tried to change configuration files order I use in web contextConfigLocation, but no luck.
    Is this specific for @Configuration configuration? I don't want to switch my application into @Configuration instead of XML, at least, if I have to, I would like to know how to fix this error.

    Please, also look into (the last answer) and
    I asked them for this issue, I describe here, but got no answers.
    Please, if anyone, has any idea or thoughts what can be wrong, share it with me, I will appreciate that much.
    Let me know, if you additional information for this issue.

  • #2
    Addition to the original post.
    Everything works fine from JUnit/Integration test, AccountRepository is @Injected (constructor injection) into AuthenticationService, and AuthenticationService is @Injected (constructor injection) into UsernamePasswordAuthenticationProvider (see attached screenshot below).
    But this doesn't work from the real web application. I suppose the reason is that UsernamePasswordAuthenticationProvider can't be constructed using one arg constructor, because at the construction time AuthenticationService is not available (if I'm right, so I am interested why AuthenticationService is not available?).
    And again, the same UsernamePasswordAuthenticationProvider without default constructor works fine for the Greenhouse application. Is @Configuration configuration very different internally to the classical XML+namespaces configuration?

    Thank you.
    Attached Files


    • #3
      Ok, Rob Winch helped me, he mentioned that this was according to the <debug/> usage issue. Watch for fix here