javax.inject.jar:依賴注入非常方便的jar包
阿新 • • 發佈:2019-01-12
用過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; } }
每次都要生成相應的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=