8

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?

Utku Özdemir
  • 7,390
  • 2
  • 52
  • 49

2 Answers2

17

Try the following, if you're willing to use an array instead of a List:

@Value("classpath*:../../cssDir/*.css")
private Resource[] cssFiles;
Andrei Stefan
  • 51,654
  • 6
  • 98
  • 89
1

For application.properties (yml) approach:

someFiles=file:/some/path/*.someExtension
user2310395
  • 297
  • 3
  • 6