SPRING @autowired抽象类

时间:2018-04-19 09:58:41

标签: spring class abstract autowired

我遇到了@autowired的问题。

接口IRole

public interface IRole {

   public abstract String getRoleName();

}

抽象类

public abstract class ARole implements IRole {

   @Autowired
   private StatusService statusService;

   public StatusEntity getStatus(String statusCode){
       return statusService.get(statusCode);
   }
}

类角色用户

@Component
public class RoleUser extends ARole {

    public String getRoleName() {
       return "USER";
    } 

    public StatusEntity getStatus() {
        return super.getStatus("PROJET");
    }
}

statusService

public interface StatusService {

StatusEntity get(String statusCode);

}

StatusServiceImpl

@Service
@Transactional
public class StatusServiceImpl implements StatusService {

@Autowired
IStatusDao dao;

@Override
public StatusEntity get(String codeStatus) {
    if (codeStatus == null) {
        throw new IllegalArgumentException();
    }

    StatusEntityPk pk = new StatusEntityPk();
    pk.setCode(codeStatus);
    return dao.findById(pk);
    }
}

我暂时尝试添加roleUser:

if(isUser(authority)){
        userRole = new RoleUser();
}

并且如果authority ='USER'

,则函数isUser返回true

但是在运行我的applcation时,我的statusService为null。 你有什么想法吗?

感谢

0 个答案:

没有答案