Koolala
Koolala

Reputation: 347

Inject Handler into annotation controller

How can I inject handler into a annotation controller(@Controller) without using @Autowire?

Upvotes: 2

Views: 695

Answers (1)

Sean Patrick Floyd
Sean Patrick Floyd

Reputation: 298838

You can of course always configure autowiring in XML:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    default-autowire="byType">

    <!-- all beans here will be autowired, including those
         found by <contect:component-scan /> -->

</beans>

But you will probably have to supply Setter methods for the properties.

Reference: Autowiring Collaborators


BTW, you can also use the JSR-250 @Resource annotation (and of course JSR-330's @Inject, thanks @Bozho) if you don't want to use Spring's proprietary @Autowired annotation.

Reference: @Resource, @Autowired and @Inject

Upvotes: 2

Related Questions