In my Spring 3.0 app, I have some resources in /WEB-INF/dir
. At runtime I need some of them as an InputStream
(or some other type). How can I retrieve them? Is it possible to inject them as a normal Resource
?
The main difference is is that @Autowired is a spring annotation whereas @Resource is specified by the JSR-250. So the latter is part of normal java where as @Autowired is only available by spring.
@Inject and @Autowired both annotations are used for autowiring in your application. @Inject annotation is part of Java CDI which was introduced in Java 6, whereas @Autowire annotation is part of spring framework. Both annotations fulfill same purpose therefore, anything of these we can use in our application. Sr.
The reasons why field injection is frowned upon are as follows: You cannot create immutable objects, as you can with constructor injection. Your classes have tight coupling with your DI container and cannot be used outside of it. Your classes cannot be instantiated (for example in unit tests) without reflection.
Here is an easiest way to do it via annotation:
import org.springframework.core.io.Resource; @Value("classpath:<path to file>") private Resource cert;
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