spring常用的组件注册为配置文件包扫描,类方法添加注解来进行组件注册
配置文件为:
<context:component-scan basepackge="要扫描的包名"/> <!--配置组件扫描-->
<!--直接在配置文件中加载bean组件(不常用)-->
<bean id="person" class="com.forever.bean.Person">
<property name="name" value="zhangsan"/>
<property name="age" value="18"/>
</bean>
新创建一个类,在类名上方加上@Controller、@Service、@Repository或者@Component来进行组件注册。