my spring.xml is as below
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
">
<context:component-scan base-package="com.mkyong.service" />
<context:annotation-config />
</beans>
and I have Test1 class
package com.mkyong.service;
import org.springframework.stereotype.Component;
@Component("test1")
public class Test1 {
public int i=1;
}
I have a App class
package com.mkyong.common;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.mkyong.service.Test1;
public class App
{
@Autowired
Test1 test1;
public static void main( String[] args )
{
ApplicationContext context = new ClassPathXmlApplicationContext(
"spring.xml");
App app=new App();
System.out.println(app.test1);
}
}
But I get the output as null.I can not Autowire it properly.Where I am doing wrong?