The best approach would be to declare the handler as a Bean, since it is assumed that the ProfileManager is already declared - and then the autowire ProfileManager in the Handler Bean, either with the @Autowired annotation if you use annotations in your application or inside applicationContext.xml. An example of how to do this in xml might be:
<bean id="profileManager" class="pckg.ProfileManager" /> <bean id="handler" class="pckg.Handler" > <property name="pm" ref="profileManager" /> </bean>
If you DO NOT want to register the Handler as a Bean, create it the same way you do and grab the pm instance from spring ApplicationContext. The way to get ApplicationContext in a web application is shown here.
source share