java 继承类之后,访问不到超类的属性的原因及解决方法
原创
©著作权归作者所有:来自51CTO博客作者大小姐的生产工厂的原创作品,请联系作者获取转载授权,否则将追究法律责任
是因为超类里的属性没有加上public关键字
解决方法: 超类和超类里的属性或者方法如果想被其他包下的方法调用,就必须全部加上public权限,即设置为公开访问
例:
@Controller
public class BaseController {
@Autowired
public AssetsService assetsService;
@Autowired
public ConfigLinuxService configLinuxService;
@Autowired
public ConfigWindowsService configWindowsService;
@Autowired
public XconfigLinuxService xconfigLinuxService;
@Autowired
public XconfigWindowsService xconfigWindowsService;
@Autowired
public ConfigWindowsWaiYunService configWindowsWaiYunService;
}
public class BaseUtil {
public AssetsService assetsService = (AssetsService) SpringContextUtil.getBean(AssetsService.class);
public ConfigLinuxService configLinuxService = (ConfigLinuxService) SpringContextUtil.getBean(ConfigLinuxService.class);
public ConfigWindowsService configWindowsService = (ConfigWindowsService) SpringContextUtil.getBean(ConfigWindowsService.class);
public XconfigLinuxService xconfigLinuxService = (XconfigLinuxService) SpringContextUtil.getBean(XconfigLinuxService.class);
public XconfigWindowsService xconfigWindowsService = (XconfigWindowsService) SpringContextUtil.getBean(XconfigWindowsService.class);
}