I have a controller superclass and its subclass:
public class SuperController {
@Resource
private A resourceA;
}
public class SubController extends SuperController {
@Resource
private B resourceB;
}
I don't use resourceA
field i开发者_开发技巧n Subcontroller
, but Subcontroller
acts as SuperController
and has the same methods. So how can I forbit the inheritance of @Resource
annotation, just like that:
public class SuperController {
**private** @Resource
private A resourceA;
}
Sounds like you need a common abstract class if the sub-class doesn't use some of the fields of the parent class.
public abstract class AbstractController {
// common fields.
// common methods.
}
public class SuperController extends AbstractController {
@Resource
private A resourceA;
}
public class SubController extends AbstractController {
@Resource
private B resourceB;
}
精彩评论