67,513
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean
class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
<bean id="springHello" class="com.spring.service.impl.SpringHello"></bean>
<bean id="mybatisHello" class="com.spring.service.impl.MybatisHello"></bean>
<bean id="helloService" class="com.spring.service.HelloService"></bean>
</beans>
public class HelloService
{
// ??? @Qualifier不起作用
@Autowired
@Qualifier("springHello")
Hello hello;
public HelloService()
{
}
//@Autowired
public HelloService(Hello hello){
this.hello = hello;
System.out.println("auto-write by constructor");
}
public Hello getHello()
{
return hello;
}
//@Autowired
public void setHello(Hello hello)
{
System.out.println("auto-write by type");
this.hello = hello;
}
}
public interface Hello
{
public void say();
}
SpringHello:
public class SpringHello implements Hello
{
public void say()
{
System.out.println("Hello Spring!");
}
}
MybatisHello:
public class MybatisHello implements Hello
{
public void say()
{
System.out.println("Hello Mybatis!");
}
}