javax.inject.jar(依赖注入非常方便的jar包)

用过Spring框架的我们都知道,每当生成依赖注入的时候,我们都必须生成相应类的set方法,而且要在set方法上面写上@Autowired,才能实现依赖注入,如下:

package com.kaishengit.web; import com.kaishengit.service.ProjectService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @Controller public class FolderController { private ProjectService projectService; //set @Autowired public void setProjectService(ProjectService projectService) { this.projectService = projectService; } }

【javax.inject.jar(依赖注入非常方便的jar包)】 每次都要生成相应的set方法感觉好麻烦,现在如果我们使用javax.inject.jar,只需要在相应类的属性上面加上@Inject,如下代码:
package com.kaishengit.web; import com.kaishengit.service.ProjectService; import org.springframework.stereotype.Controller; import javax.inject.Inject; @Controller public class FolderController { @Inject private ProjectService projectService; }

javax.inject.jar下载地址:https://code.google.com/p/dependency-shot/downloads/detail?name=javax.inject.jar&can=2&q=

    推荐阅读