<?xml version="1.0" encoding="UTF-8"?> <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 https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.nbg.pojo"/>
<context:annotation-config/>
<bean id="name" class="java.lang.String">
<constructor-arg value="张大仙" name="value"/>
</bean>
</beans>
@Autowired:相当于byName;配合required=false使用,说明该值可以为null;
@Nullable:说明这个字段可以为null;
@Qualifier(名称):需要配合@Autowired一起使用;用于名称不一样;
@Resource:先通过名称寻找,在通过类型匹配,如果都没找到就报错;或者@Resource(name = "")
@Component:零件;表示该部分被注解了
衍生注解:
dao:@Repository
service:@Service
controller:@Controller
@Value("值")
@Scope(“单例/原生...等”)