以下是我的代码:
case BrowserType.PhantomJS:
var service = PhantomJSDriverService.CreateDefaultService(Path.Combine(_rootPath, @"Packages\"));
var cookieFilePath=Path.Combine(_rootPath, @"Packages\cookie.txt");
if (!File.Exists(cookieFilePath))
File.Create(cookieFilePath);
var phantomjsoptions = new PhantomJSOptions();
driver = new PhantomJSDriver(service,phantomjsoptions);
var cookieJar = driver.Manage().Cookies;
driver.Navigate().GoToUrl(SeleniumConfiguration.Current.BaseURL);
cookieJar.AddCookie(new Cookie("x", "12345"));
return driver;
Run Code Online (Sandbox Code Playgroud)
基本上问题是我无法登录我的测试应用程序因为我收到错误说 -
"您的浏览器设置为阻止Cookie"
我已经尝试了一切,但我似乎无法得到解决方案.
我该怎么办?
请帮帮我.
如果遗漏了一些细节,请告诉我.
我是春季靴的新手。因此,在从spring initializr引导项目后,我试图在intellij上运行它。但是启动时出现错误。
以下是版本:
Java:8
Spring-boot:2.0.6
我尝试更改Spring Boot的版本,但没有帮助。
还更改了application.properties中的服务器端口,但这也无济于事。
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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>ghosh.debarshi</groupId>
<artifactId>spring5webapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring5webapp</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<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>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
Description:
Failed to …Run Code Online (Sandbox Code Playgroud) private static final Map<String, SampleClass> map = new
ConcurrentHashMap<>();
public static SampleClass getsampleclass(String context) {
if( map.get(context) != null) {
return map.get(context);
} else {
SampleClass cls = new SampleClass(context);
map.put(context, cls);
}
}
Run Code Online (Sandbox Code Playgroud)
在多线程环境中,如果两个线程获取map.get(context)为null,则两个线程都将创建cls,并且put将被阻塞,因此thread1将首先放置,之后thread2将覆盖放置的内容thread1.
这种行为是否正确?
在我的情况下,我想在map.get完成后返回相同的值,因此我看到使用HashMap和同步它是首选.