gpt4 book ai didi

spring - 如何通过 HTTPS 通过 Maven Tomcat7 运行 Spring 应用程序?

转载 作者:行者123 更新时间:2023-11-28 22:41:42 24 4
gpt4 key购买 nike

为了启用 HTTPS,我使用 keytool -genkey 创建了自签名 ssl 证书,然后在 pom.xml 中进行了相同的配置

在 pom.xml 中,我使用了以下代码:

<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<!-- application path always starts with / -->
<path>/</path>
<!-- http port -->
<port>8080</port>
<httpsPort>8443</httpsPort>
<keystoreFile>src/main/tomcatconf/xxx.keystore</keystoreFile>
<keystorePass>xxx123</keystorePass>
<warRunDependencies>
<warRunDependency>
<dependency>
<groupId>a groupId</groupId>
<artifactId>and artifactId</artifactId>
<version>version</version>
<type>war</type>
</dependency>
<contextPath>/</contextPath>
</warRunDependency>
</warRunDependencies>

<enableNaming>true</enableNaming>

<extraDependencies>
<extraDependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.1.3.1</version>
</extraDependency>
<extraDependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</extraDependency>
</extraDependencies>
</configuration>

</plugin>

但是没有成功,然后我在 pom.xml 中使用了 serverXml 参数,并在 webapps 路径中添加了 server.xml 文件。

  <?xml version='1.0' encoding='utf-8'?>
<Server port="${shutdown.port}" shutdown="SHUTDOWN">

<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

<Listener
className="com.springsource.tcserver.serviceability.rmi.JmxSocketListener"
port="${jmx.port}" bind="127.0.0.1" useSSL="false"
passwordFile="${catalina.base}/conf/jmxremote.password" accessFile="${catalina.base}/conf/jmxremote.access"
authenticate="true" />

<Listener
className="com.springsource.tcserver.serviceability.deploy.TcContainerDeployer" />

<Listener className="org.apache.catalina.core.AprLifecycleListener"
SSLEngine="on" />

<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>


<Service name="Catalina">

<Executor name="tomcatThreadPool" namePrefix="tomcat-http--"
maxThreads="300" minSpareThreads="50" />


<Connector SSLEnabled="true" acceptCount="100"
connectionTimeout="20000" executor="tomcatThreadPool" keyAlias="tcserver"
keystoreFile="${catalina.base}/conf/xxx.keystore" keystorePass="xxx123"
maxKeepAliveRequests="15" port="${bio-ssl.https.port}"
protocol="org.apache.coyote.http11.Http11Protocol" redirectPort="${bio-ssl.https.port}"
scheme="https" secure="true" />

<Connector port="8080" protocol="AJP/1.3" redirectPort="8443" />

<Engine name="Catalina" defaultHost="localhost">

<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase" />

<Host appBase="webapps" autoDeploy="true" deployXML="false"
name="localhost" unpackWARs="true">
<Context docBase="../../webapp" path="/webapp" reloadable="true" />
</Host>

</Engine>
</Service>

同样,第二种方法也没有奏效,所以尝试了另一种方法,我尝试使用 keytool-maven-plugin 在 pom.xml 本身中生成 keystore 。

为此,我在 pom.xml 中添加了以下代码:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>keytool-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>generate-resources</phase>
<id>clean</id>
<goals>
<goal>clean</goal>
</goals>
</execution>
<execution>
<phase>generate-resources</phase>
<id>genkey</id>
<goals>
<goal>genkey</goal>
</goals>
</execution>
</executions>
<configuration>
<keystore>${project.build.directory}/tomcat-ssl.keystore</keystore>
<dname>cn=localhost</dname>
<keypass>tomcat-learn</keypass>
<storepass>tomcat-learn</storepass>
<alias>tomcat-learn</alias>
<keyalg>RSA</keyalg>
</configuration>
</plugin>


<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<!-- application path always starts with / -->
<path>/</path>
<!-- http port -->
<port>8080</port>
<httpsPort>8443</httpsPort>
<keystoreFile>${project.build.directory}/tomcat-ssl.keystore</keystoreFile>
<keystorePass>tomcat-learn</keystorePass>
<warRunDependencies>
<warRunDependency>
<dependency>
<groupId>a groupId</groupId>
<artifactId>and artifactId</artifactId>
<version>version</version>
<type>war</type>
</dependency>
<contextPath>/</contextPath>
</warRunDependency>
</warRunDependencies>

<enableNaming>true</enableNaming>

<extraDependencies>
<extraDependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.1.3.1</version>
</extraDependency>
<extraDependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</extraDependency>
</extraDependencies>
</configuration>

</plugin>

同样,上面的第三个方案也没有解决,请帮我解决我用过的三个方法中的任何一个。请提出一个方法。

提前致谢。

最佳答案

你好Nayana_Das ,

我设法通过这样做让它工作:

pom.xml

    <build>

<pluginManagement>

<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/manager</url>
<server>localhost</server>
<path>/${project.build.finalName}</path>
</configuration>
</plugin>

</plugins>

</pluginManagement>

<!-- To use the plugin goals in your POM or parent POM -->
<plugins>

<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<path>/</path>
<port>8080</port>
<httpsPort>8443</httpsPort>
<keystoreFile>${project.build.directory}/tomcat7.keystore</keystoreFile>
<keystorePass>tomcat7</keystorePass>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>keytool-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>generate-resources</phase>
<id>clean</id>
<goals>
<goal>clean</goal>
</goals>
</execution>
<execution>
<phase>generate-resources</phase>
<id>genkey</id>
<goals>
<goal>generateKeyPair</goal>
</goals>
</execution>
</executions>
<configuration>
<keystore>${project.build.directory}/tomcat7.keystore</keystore>
<dname>cn=localhost</dname>
<keypass>tomcat7</keypass>
<storepass>tomcat7</storepass>
<alias>tomca7</alias>
<keyalg>RSA</keyalg>
</configuration>
</plugin>
</plugins>
  1. 为tomcat插件执行tomcat7:run;
  2. 打开浏览器并输入 https://localhost:8443/yoururl (如果有网址);
  3. 它会提示安全问题,继续;

关于spring - 如何通过 HTTPS 通过 Maven Tomcat7 运行 Spring 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30295658/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com