Announcement Announcement Module
Collapse
No announcement yet.
Autowire/injection not working Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Autowire/injection not working

    hi everyone,

    Can anyone help me here the autowiring is not working


    This is the configuration file

    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schem...-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan base-package="com.bosch.in.InputChannel" />

    <context:annotation-config/>



    <bean id="Test" class="Test" />

    <bean id="httpClient" class="org.apache.commons.httpclient.HttpClient" />

    <bean id="httpChannel" class="httpChannel" >

    </bean>



    <bean id="httpChannelHelper" class="httpChannelHelper">
    </bean>


    </beans>



    This is the class were the inhection of setHttpChannelHelper is not working


    public class HttpChannel implements IChannel
    {

    public HttpChannelHelper httpChannelHelper;



    public HttpChannelHelper getHttpChannelHelper()
    {
    return httpChannelHelper;
    }

    @Autowired
    public void setHttpChannelHelper(HttpChannelHelper httpChannelHelper) {

    this.httpChannelHelper = httpChannelHelper;

    }

    public HttpChannel()throws Exception
    {

    }


    public static void main(String args[])
    throws Exception
    {
    ApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext .xml");




    int exitCode = (new HttpChannel()).read(1);

    System.out.println(exitCode);

    }

  • #2
    First I see
    <context:component-scan base-package="com.bosch.in.InputChannel" />

    base-package is to have a package to scan, you wrote InputChannel, that doesn't sound like a package to me, it sounds like a class.

    Also you don't need <context:annotation-config/> component-scan is a superset over annotation-config. So annotation-config in that case is redundant.

    Mark

    Comment


    • #3
      Hi bytor,


      it is a package ,just naming mistake .. Can you give me a idea why the object is not getting injected . And also does autowiring works only in server environment coz mine is not a server application .

      Comment


      • #4
        Spring container works the same regardless of environment you are running in.

        I keep looking at your configuration and seeing things that aren't correct. Probably when you typed it in the post, maybe not so in your actual xml file.

        For instance

        <bean id="httpChannel" class="httpChannel" >

        </bean>

        class="httpChannel"???? Isn't your class HttpChannel, no lower case "h"

        and is this class in a package?

        It might be easier to post your actual xml file copied and pasted exactly as it is in the xml file. Make sure to use the CODE tags when posting it so it is readable to us.

        Mark

        Comment


        • #5
          Spring container works the same regardless of environment you are running in.

          I keep looking at your configuration and seeing things that aren't correct. Probably when you typed it in the post, maybe not so in your actual xml file.

          For instance

          <bean id="httpChannel" class="httpChannel" >

          </bean>

          class="httpChannel"???? Isn't your class HttpChannel, no lower case "h"

          and is this class in a package?

          It might be easier to post your actual xml file copied and pasted exactly as it is in the xml file. Make sure to use the CODE tags when posting it so it is readable to us.

          Mark

          Comment

          Working...
          X