嗨,有这样的spring启动项目和控制器
@RestController
@RequestMapping(value= "/test")
public class AuthenticationController {
@RequestMapping(value = "/ping", method = RequestMethod.GET)
public String ping(HttpServletRequest request) {
String result = "HttpServletRequest.hashCode(): " + request.hashCode();
return result;
}
}
从浏览器的REST客户端到API/test/ping的所有请求都返回相同的值
HttpServletRequest.hashCode()
.
为什么会这样?我在网上查了很多资料,但找不到原因。
我找到的唯一信息是“创建和管理HttpServletRequest和response对象并重用它们的servlet容器”。但不一定总是这样,每次请求都会发生,不管我等了多久。
以下是一些设置信息:
部署在Tomcat8.5上
servlet.xml文件
<Connector SSLEnabled="true" acceptCount="100" compression="on" disableUploadTimeout="true" enableLookups="false"
maxHttpHeaderSize="8192" maxThreads="550" minSpareThreads="25" port="443"
protocol="org.apache.coyote.http11.Http11NioProtocol" scheme="https" secure="true"
sslImplementationName="org.apache.tomcat.util.net.openssl.OpenSSLImplementation">
<UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol"/>
<SSLHostConfig certificateVerification="none"
ciphers="TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA"
protocols="TLSv1.2">
<Certificate
certificateKeyAlias="*hidden"
certificateKeystoreFile="hidden"
certificateKeystorePassword="hidden" type="RSA" />
</SSLHostConfig>
ââ
</Connector>
主持人
<Host appBase="hidden" name="hidden.net">
<Context docBase="../somewebapp" path="/webapp" reloadable="false"/>
</Context>
</Host>
pom.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>**hidden**</groupId>
<artifactId>**hidden**</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>**hidden**</name>
<description>**hidden**</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Tests: Selenium & TestNG -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src\test\resources\suites\RegressionSuite.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>