如何配置Wildfly提供静态内容(如图片)?
问题描述:
我有一个在Wildfly 8.0.0 Final上运行的JavaEE应用程序.
I have a JavaEE application running on Wildfly 8.0.0 Final.
该应用程序使用大量图像,我不想将它们存储在数据库中,因此将它们写入硬盘.
The application uses a lot of images and I don't want to store them in the database, so they are written to the hard disk.
如何配置Wildfly/Undertow,以便在特定的URL(例如http://localhost:8080/myapplication/imagesFromDisk
)上投放这些文件(/var/图像)?
How can I configure Wildfly/Undertow in order to serve these files (/var/images) on a certain URL, for example http://localhost:8080/myapplication/imagesFromDisk
?
答
在standalone.xml中向undertow子系统添加另一个文件处理程序和另一个位置:
Add another file handler and another location to the undertow subsystem in standalone.xml:
<server name="default-server">
<http-listener name="default" socket-binding="http"/>
<host name="default-host" alias="localhost">
<location name="/" handler="welcome-content"/>
<location name="/img" handler="images"/>
</host>
</server>
<handlers>
<file name="welcome-content" path="${jboss.home.dir}/welcome-content" directory-listing="true"/>
<file name="images" path="/var/images" directory-listing="true"/>
</handlers>