java spring学习笔记

用java spring框架开发web Service的学习笔记


1. ApplicationContext中可以使用来自动将@Service @Controller @Repository等标注的类

注册成bean,

也可以手动注册bean,语法如下



test


其中property的name在类中有同名的变量,会自动映射过去。


2. 一个Service接口,多个实现类的话,使用@autowired会出现问题,因为无法决定到底使用哪个,解决方案如下

@Service(value="firstimpl")

class ....  implement interface {}

@Service (value="secondimpl")

class ...  implement interface {}

使用的时候

@Autowired

@Qualifier("firstimpl")

interface inte1;

或者更elegant的方法是

@Resource(name="firstimpl")

interface inte2;


你可能感兴趣的:(Java)