我在我的 tomcat 生产服务器上使用强制 ssl 配置。我想在开发中禁用此功能,并想知道我的选择是什么。配置发生在我的 web.xml 文件中。我目前使用 Maven 构建我的项目,所以我已经有一些配置文件,我更喜欢在其中设置设置。
最佳答案
在您的 web.xml 中的某处,您可能具有以下设置:
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
如果是这样,您可以为传输保证属性使用属性占位符,并在构建期间对其进行资源过滤。将 web.xml 中的那一行替换为:
<transport-guarantee>${transport.guarantee}</transport-guarantee>
您可以为 pom 文件或外部属性文件中的属性 ${transport.guarantee} 分配默认值(可以是“CONFIDENTIAL”),并通过提供命令行参数在开发环境中覆盖它:
mvn clean package -Dtransport.guarantee="NONE"
如果您正在使用 maven war 插件,可以通过以下方式从 pom 文件中启用资源过滤:
<configuration>
<webResources>
<resource>
<filtering>true</filtering>
<directory>src/main/webapp</directory>
<includes>
<include>**/web.xml</include>
</includes>
</resource>
</webResources>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
最后,如果您必须使用现有配置文件,则根据激活的配置文件设置 transport.guarantee 的值。一种方法:
<profiles>
<profile>
<id>development</id>
<properties>
<transport.guarantee>NONE</transport.guarantee>
</properties>
</profile>
<profile>
<id>production</id>
<properties>
<transport.guarantee>CONFIDENTIAL</transport.guarantee>
</properties>
</profile>
您希望将生产配置文件设置为默认设置为事件。使用 ~/.m2/settings.xml 文件覆盖并激活您的开发配置文件。
关于maven - 配置文件相关的 web.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18443302/