2 beans with same name but in different packages; how to autowire them?

You will have to give your beans different names - if multiple beans are defined with the same name, then the one defined later will override the one defined earlier - so in your case only one bean will exist with the name of dataTransferHandler.

You can give these two beans different names, so that both can exist and you can inject in the correct one either using: @AutoWired @Qualifier("dataTransferHandler") OR @Resource(name="dataTransferHandler")


You can give attribute primary="true" to the bean defination you want to have the preference when autowired. But the bean names must be different. There is no solution for same bean name.

At run-time when you will get the autowired class then the primary true bean will get the preference for autowiring. Hope this helps you. Cheers.