I’m new to Spring 3, and its fancy additional annotations in particular
I have no idea how to have a controller class B, that extends controller class A, where A is defined via the xml files to have something useful – say, a db connection or whatever.
If I have an (abstract) parent bean A, and a concrete bean B, and B is a controller, AND i’m using the annotations-auto-wiring (you know,
<context:component-scan base-package="package"/>
), can I somehow tie B to A? Do i use annotations? Where do i define A, given that A needs to have some random spring bean put into it?
Having a database connection in your controller, as @Shakedown mentions, is a bad practice. I know it’s just an example, but I wanted to make sure that was pointed out.
With Spring annotations, you can get away from XML almost completely, for most projects.
It is common to have an
AbstractControllerclass, from which other concrete classes are derived.Dependencies can be injected into Spring classes using the
@Autowiredannotation. If you want to inject dependencies into your AbstractController, which is not technically a Spring managed class – you can make it one simply by adding the@Componentannotation.You can then use the dependency in your subclasses.