I have a class which I use as a spring bean. The bean is defined in the applicationContext.xml
like:
<bean id="myClass" class="com.example.MyClass">
<property name="cssFiles" value="classpath*:../../cssDir/*.css"/>
</bean>
And MyClass
looks like:
...
import org.springframework.core.io.Resource;
...
public class MyClass {
private List<Resource> cssFiles;
// methods etc.
}
So Spring populates the cssFiles field with all the files with .css extension under "classpath*:../../cssDir/" .
Now I am working on moving to full annotation configuration, but I could not manage to do the same thing with annotations. This does NOT work:
...
import org.springframework.core.io.Resource;
...
@Component
public class MyClass {
@Value("classpath*:../../cssDir/*.css")
private List<Resource> cssFiles;
// methods etc.
}
Do you have any idea?
1. Overview In this Spring Framework tutorial, we'll demonstrate how to use annotations related to dependency injection, namely the @Resource, @Inject, and @Autowired annotations. These annotations provide classes with a declarative way to resolve dependencies: As opposed to instantiating them directly (the imperative way):
If @Resource annotation is not using name attribute, Spring accesses other beans for matching them by type. 6. The @Resource can be used on a a. Field b. Method 7. The @Resource can be used by b. type attribute. 1. In Spring, the JSR-250 @Resource and Spring @Autowired both annotations are used to solve dependency injection.
In Spring, the JSR-250 @Resource and Spring @Autowired both annotations are used to solve dependency injection. The @Resource is supported only for fields and bean property setter methods with a single argument whereas @Autowired applies to fields, constructors, and multi-argument methods. 2.
This Spring tutorial helps you understand how to use Java annotations to configure dependency injection for classes in an application. Besides using XML for dependency injection configuration, Spring also allows programmers to embed some special annotations into Java classes to do the same thing.
Try the following, if you're willing to use an array instead of a List
:
@Value("classpath*:../../cssDir/*.css")
private Resource[] cssFiles;
For application.properties (yml) approach:
someFiles=file:/some/path/*.someExtension
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With