将一些文件资源注入Spring bean的好方法是什么?现在我自动装配ServletContext并使用如下所示.在Spring MVC中更优雅的方式吗?
@Controller
public class SomeController {
@Autowired
private ServletContext servletContext;
@RequestMapping("/texts")
public ModelAndView texts() {
InputStream in = servletContext.getResourceAsStream("/WEB-INF/file.txt");
// ...
}
}
Run Code Online (Sandbox Code Playgroud)