Announcement Announcement Module
Collapse
No announcement yet.
Getting null for auto injected object inside method triggered by SI method call Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Getting null for auto injected object inside method triggered by SI method call

    Let me explain the issue. The function being called by SI channels is as follows

    Code:
    class OrganizationBOBean 
    {
      ...............
     @Required
        public void setOrganizationDAO(OrganizationDAO organizationDAO) {
            this.organizationDAO = organizationDAO;
        }
    
    
     public String  getCompanyCountName(String companyName)
        {
        	String cc ;
        	cc = (String)organizationDAO.getCompanyCountByName(companyName);
        	return cc ;
      } 
    ....................
    }
    getCompanyCountName is method of bean ref getcompcount
    Code:
    <int:service-activator  input-channel="inputChannel" ref="getcompcount"
    		method="getCompanyCountName" output-channel="outputChannel">
    
    
    <beans:bean id="getcompcount"
    			class="com.mexx.org.OrganizationBOBean" />
    the object organizationDAO is an auto injected object through setter method as being shown above.


    when the function getCompanyCountName is trigerred by SI channels I am getting organizationDAO as null. How could I explicitly call the setter method runtime to create the organizationDAO object when there is a SI call.
    Last edited by Gary Russell; Jun 13th, 2013, 05:05 AM.

  • #2
    When SI is creating an object its not auto injecting the dependencies from servlet context.
    How to overcome ???

    Comment


    • #3
      I presume you mean this configuration is in the main application context and the DAO is in the servlet context.

      The main context can't "see" beans in the child (servlet) context; but the servlet can see beans in the main context.

      Adding <context:annotation-config/> to the servlet context does not enable it in the main context.

      The DAO etc should be in the main context so that beans in both the main and servlet context can use it.

      Also, just adding '@Required' isn't enough - that's used to verify it was supplied; you need @Autowired.

      Comment


      • #4
        Is there any way to call the beans runtime from servlet context inside code ?

        Please let me know.

        Comment


        • #5
          Is there any way to call the beans runtime from servlet context inside code ?
          Code:
          WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext).getBean("beanId");
          Is it appropriate to you?

          Take care,
          Artem

          Comment


          • #6
            If your bean is defined in the main context, it cannot access beans in the child (servlet) context. Beans in the servlet context can get references to beans in the main context.

            Comment


            • #7
              I think its. But how to get the servletContext object ??

              regards,
              Surath

              Comment


              • #8
                But how to get the servletContext object ??
                E.g. via ServletContextAware

                Comment

                Working...
                X