我遇到了@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。 你有什么想法吗?
感谢