我想访问一些不在服务器文档根目录下的文件。
我有这个Bean
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory(){
然后我找到了班级
org.apache.catalina.core
Class StandardContext
java.lang.Object
org.apache.catalina.util.LifecycleBase
org.apache.catalina.util.LifecycleMBeanBase
org.apache.catalina.core.ContainerBase
org.apache.catalina.core.StandardContext
实现方法:
public void setAliases(String aliases)
Set the current alias configuration. The list of aliases should be of the form "/aliasPath1=docBase1,/aliasPath2=docBase2" where aliasPathN must include a leading '/' and docBaseN must be an absolute path to either a .war file or a directory.
但是如何在Spring MVC实现中获得StandardContext?
我通过创建包含Tomcat的war.file来部署我的服务器。
答案 0 :(得分:0)
这是我终结的解决方案:
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory(){
@Override
protected void postProcessContext(Context context) {
...
StandardContext sContext = (StandardContext) context;
sContext.setAliases( "/files=/home/myuser/files");
}
};
...
return tomcat;
}