spring annotation 注入static 屬性
阿新 • • 發佈:2019-01-05
第一種方法:
@Component
public class UserUtils
{
private static UserAccessor userAccessor;
/**
* Sets the user DAO. This method should never be called except by Spring
* @param userAccessor The user accessor to set
*/
@Autowired(required = true)
public void setUserAccessor(userAccessor UserAccessor) {
UserUtils.userAccessor = userAccessor;
}
}
第二種方法:
@Component
public class UserUtils
{
private static UserAccessor userAccessor;
@Autowired(required = true)
public UserUtils(@Qualifier(“userAccessorImpl”) userAccessor UserAccessor) {
UserUtils.userAccessor = userAccessor;
}
}