Announcement Announcement Module
Collapse
No announcement yet.
Spring, XML beans call Annotation beans when app start Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring, XML beans call Annotation beans when app start

    I have one Annotation bean with some methods. It works fine.
    Code:
    public @Controller("adminController") class AdminController {
    
    ...
    private @Autowired AdminDAO adminDAO;
    
    public void resetTemporalList() {
    
        System.out.println("HE SIDO EJECUTADO.");
    
        this.adminDAO.resetTemporalRegisters();
    }
    
    ...
    
    }
    Now, I am integrating one quartz task. But I am load it with XML definition beans that call previus annotation bean.
    Code:
    <bean id="resetTemporalRegisters" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="adminController" />
        <property name="targetMethod" value="resetTemporalList" />
        <property name="concurrent" value="false" />
    </bean>
    Whan I start my app appear next error.

    Caused by: org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'adminController' is defined

    I believe the problem is that Spring load XML beans first, after Annotation beans, then in this moment "adminController" bean not exits...

    How Can I fix it?

    PD: AdminDAO extends BaseDAO and use one personal annotation to do it.
    Code:
    public @Repository(value="baseDAO") abstract class BaseDAO {
    
        private @Autowired HibernateTemplate hibernateTemplate;
    
        public HibernateTemplate getHibernateTemplate() {
            return this.hibernateTemplate;
        }
    }
    Code:
    @Parent(parent = "baseDAO")
    public @Repository class AdminDAO extends BaseDAO {
    public boolean resetTemporalRegisters(){
    
    try{...
    
            this.getHibernateTemplate().find(hql);
        }catch(Exception ex){
            ex.printStackTrace();
            return false;
        }
    
        return true;
    }
    
    }

  • #2
    Your post doesn't show any configuration that actually scans for the annotations, such as:

    Code:
     <context:component-scan base-package="your.package"/>
    If this is being done in a different context file, are you importing this into your quartz context?

    When you say the annotated bean all works fine how are you testing this - are you autowiring the AdminController into a test case using the same context configuration as the quartz task is using?

    Comment


    • #3
      Sorry, I resolved it yesterday, problem was I put xml beans in applicationContext.xml. Put them in dispatcher-servlet work fine!

      Comment

      Working...
      X