一.Controller层注入Service
问题:未获取bean
常见的获取bean有两种方式
1.通过注解注入
2.通过xml配置
注解注入:扫描Controller层,然后注入Service对象
@Controller //web层
//@Autowired
private RoleService roleService;// RoleService 必须先创建bean 然后在注入
public void setRoleService(RoleService roleService) {
this.roleService = roleService;}
xml配置
<bean id="roleController" class="com.itheima.controller.RoleController"> <!--不采用注解 必须有set方法无参构造 -->
<property name="roleService" ref="roleService"></property>
</bean>