@autowired 按类型注入 多个实现类抛异常
@Qualifier(“roleService2”) 按bean注入
privae RoleService roleService2;
@Component
@Primary 首选注入 多个实现类抛异常
public class RoleServiceImol implenments RoleService;
@Bean 自定义bean的初始化和销毁,不可以用在类上只能用在方法上
@Bean(name=“role”,initMethod=“init”,destroyMethod=“myDestroy”)
public User initRole2(){
Role role = new Role();
role,setName(“11”);
return role;
}
@Profile(“dev”)配置
在XML中配置
<beans profile="dev">
<bean >
</bean>
</beans>
启动profile (需要在虚拟机配置启动) 也可以在web.Xml中配置
@ActiveProfile(“dev”)
web的环境参数
...
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>test</param-value>
</context-param>
...
使用springMVC的DispatcherServlet环境参数
<servlet>
...
...
<init-param>
<param-name>spring.profiles.active</param-name>
<param-value>test</param-name>
</init-param>
</servlet>