Spring中@Component注解,@Controller注解详解

  在使用Spring的过程中,为了避免大量使用Bean注入的Xml配置文件,我们会采用Spring提供的自动扫描注入的方式,只需要添加几行自动注入的的配置,便可以完成

Service层,Controller层等等的注入配置.使用过程中,在Service层中的实现类头上加@Compopnet注解,在Controller类头加@Controller注解,,便完成了配置。例如在

Controller中当我们调用某个Service时就不需要Set方法了,直接通过@Autowried 注解对Service对象进行注解即可:例如

在Controller中:

@Controller@RequestMapping(“/test”)public class ExampleController {@Autowiredprivate ExampleService service;}涉水而过的声音此次想起,

Spring中@Component注解,@Controller注解详解

相关文章:

你感兴趣的文章:

标签云: