不知道做了什么,@Autowired注解都无效了,求大神指教
以下是测试项目中的代码:
@Component
public class vbnm extends HttpServlet
{
public vbnm()
{
System.out.println("注入");
}
@Autowired
p person;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
System.out.println("------------------------------");
person.say();
System.out.println("------------------------------");
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
}
}
接口:public interface p
{
public void say();
}
实现类:@Component
public class Person implements p
{
private String name;
public Person()
{
System.out.println("注入ioc容器");
}
/**
* @return the name
*/
public String getName()
{
return name;
}
/**
* @param name
* the name to set
*/
public void setName(String name)
{
this.name = name;
}
public void say()
{
System.out.println("hello " + name);
}
}
spring配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
<context:component-scan base-package="de.sheng"></context:component-scan>
<context:annotation-config />
</beans>