Announcement Announcement Module
Collapse
No announcement yet.
@Autowired stop working after adding @PreAuthorize Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Autowired stop working after adding @PreAuthorize

    Hi,

    I have thi class bellow:

    --------------------------------------------This is working-----------------------------------------
    class A {
    public void method() {

    }
    }

    class B {
    @Autowired
    private A a;
    }
    ------------------------------------------This made my program not work--------------------------------------------
    class A {
    @PreAuthorize("hasRole('administrator')")
    public void method() {

    }
    }

    class B {
    @Autowired
    private A a;
    }
    -----------------------------------------------------------------------------------------------------
    -----------------------------------This is the error-----------------------

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.web.servlet.mvc.support.Contr ollerClassNameHandlerMapping#0' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'com.virtusventures.daycare.controller.StaffContro ller#0': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Could not autowire field: com.CLASSA com.CLASSB.classa; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No matching bean of type [com.CLASSA] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Aut owired(required=true)

    NOTE:
    My program works when i remove the preauthorise annotation method security.

    HELPPPPP me guys
Working...
X