I would say that we do prefer @Autowired over manual injection for
almost everything since it makes your Spring context files much smaller.
We would like to have all of the main daemon classes using @Autowired,
especially when they access the DAO classes since we generally only have
a single implementation of the DAO classes (Hibernate impl) and they are
easy to identify by name or classname throughout the code. Not all of
the code is using @Autowired yet; if anyone is interested in providing
pull requests that implement this, it would be appreciated. :)

Autowiring also prepares us for the near future where almost every wired
field will be accessed as an OSGi service. The new OSGi code already
works this way when it accesses DAO classes and this has proven to be an
easy environment to wire up.

-- Seth


On 5/14/13 3:13 PM, vivek nalla wrote:
> Hi Seth
>
> Thanks for the explanation. I want to add a note that some people don't
> prefer using autowired annotation because it doesn't gives a tight control
> over the code and there are some spring issues while generating the
> dependency tree of beans in particular scenarios.
>
>
> On Tue, May 14, 2013 at 11:26 PM, Seth Leger <s...@opennms.org> wrote:
>
>>  Hi Nalla,
>>
>> We do not have a strong convention for how to do autowiring but there are
>> some general guidelines. You would want to use constructor wiring for
>> constant, final values that will not change over the lifetime of the
>> object. Constructor wiring is also good if the class only has 1 or 2 fields
>> that need to be injected since the constructors stay small. We don't really
>> want constructors with 5 or more arguments because that makes it difficult
>> to wire them with mock objects for unit tests. If you have that many
>> fields, use getter/setter injection instead.
>>
>> As far as field versus getter/setter wiring... I think at this point that
>> most of the OpenNMS code uses getter/setter wiring even though it requires
>> more lines of code. It's a little better because it follows the old
>> javabean conventions and is easier for most developers to read.
>>
>> Seth Leger
>> The OpenNMS Group
>>
>>
>>
>> On 5/14/13 1:25 PM, vivek nalla wrote:
>>
>> Hi,
>>
>> Is there any recommended way of using autowired across OpenNMS source code.
>> Is Constructor autowiring preferred over setter autowiring and field
>> autowiring or it depends on the specific use case.
>>
>> Thanks,
>> Nalla.
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> AlienVault Unified Security Management (USM) platform delivers complete
>> security visibility with the essential security capabilities. Easily and
>> efficiently configure, manage, and operate all of your security controls
>> from a single console and one unified framework. Download a free 
>> trial.http://p.sf.net/sfu/alienvault_d2d
>>
>>
>>
>> _______________________________________________
>> Please read the OpenNMS Mailing List 
>> FAQ:http://www.opennms.org/index.php/Mailing_List_FAQ
>>
>> opennms-devel mailing list
>>
>> To *unsubscribe* or change your subscription options, see the bottom of this 
>> page:https://lists.sourceforge.net/lists/listinfo/opennms-devel
>>
>>
>>


------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
_______________________________________________
Please read the OpenNMS Mailing List FAQ:
http://www.opennms.org/index.php/Mailing_List_FAQ

opennms-devel mailing list

To *unsubscribe* or change your subscription options, see the bottom of this 
page:
https://lists.sourceforge.net/lists/listinfo/opennms-devel

Reply via email to