1. The
problem of injecting Service at the Controller layer:
There are two common ways to obtain a bean without obtaining a bean:
1. Inject through annotations
2. Configure
annotation injection through xml : scan the Controller layer, and then inject the Service object
@Controller //web层
//@Autowired
private RoleService roleService;// RoleService 必须先创建bean 然后在注入
public void setRoleService(RoleService roleService) {
this.roleService = roleService;}
xml placement
<bean id="roleController" class="com.itheima.controller.RoleController"> <!--不采用注解 必须有set方法无参构造 -->
<property name="roleService" ref="roleService"></property>
</bean>