How to Autowire Bean of generic type in Spring?

Simple solution is to upgrade to Spring 4.0 as it will automatically consider generics as a form of @Qualifier, as below: @Autowired private Item<String> strItem; // Injects the stringItem bean @Autowired private Item<Integer> intItem; // Injects the integerItem bean Infact, you can even autowire nested generics when injecting into a list, as below: // Inject … Read more

Exclude subpackages from Spring autowiring?

I’m not sure you can exclude packages explicitly with an <exclude-filter>, but I bet using a regex filter would effectively get you there: <context:component-scan base-package=”com.example”> <context:exclude-filter type=”regex” expression=”com\.example\.ignore\..*”/> </context:component-scan> To make it annotation-based, you’d annotate each class you wanted excluded for integration tests with something like @com.example.annotation.ExcludedFromITests. Then the component-scan would look like: <context:component-scan base-package=”com.example”> … Read more

@Autowired – No qualifying bean of type found for dependency

You should autowire interface AbstractManager instead of class MailManager. If you have different implemetations of AbstractManager you can write @Component(“mailService”) and then @Autowired @Qualifier(“mailService”) combination to autowire specific class. This is due to the fact that Spring creates and uses proxy objects based on the interfaces.

Spring injects dependencies in constructor without @Autowired annotation

Starting with Spring 4.3, if a class, which is configured as a Spring bean, has only one constructor, the @Autowired annotation can be omitted and Spring will use that constructor and inject all necessary dependencies. Regarding the default constructor: You either need the default constructor, a constructor with the @Autowired annotation when you have multiple … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)