我在 logback.xml 中将此配置放入 Spring Web 应用程序(无 Spring Boot)。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.contrib.json.classic.JsonLayout">
<timestampFormat>yyyy-MM-dd'T'HH:mm:ss.SSSX</timestampFormat>
<timestampFormatTimezoneId>Etc/UTC</timestampFormatTimezoneId>
<jsonFormatter class="ch.qos.logback.contrib.jackson.JacksonJsonFormatter">
<prettyPrint>true</prettyPrint>
</jsonFormatter>
</layout>
<customFields>{"appname":"foobar"}</customFields>
</encoder>
</appender>
<!-- LOG everything at INFO level -->
<root level="INFO">
<appender-ref ref="Console" />
</root>
</configuration>
Run Code Online (Sandbox Code Playgroud)
JSON 布局工作正常,但不会打印“appname”:“foobar”这样的自定义字段:
{
"timestamp" : "2020-06-10T14:55:25.534Z",
"level" : "INFO",
"thread" : "Catalina-utility-1",
"logger" : "org.springframework.web.servlet.DispatcherServlet",
"message" : "FrameworkServlet 'dispatcher': initialization completed in 72 ms",
"context" : "default"
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
解决方案
我使用了错误的库来满足我的需求:
由于我需要通过 Logstash 处理日志,因此我更正了我的配置,如下所示:
pom.xml …
嗨,我遇到了Google Cloud的Java SDK库问题。
我需要查询Dialogflow V2 API,并且正在使用此SDK(https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master)
我已按照说明进行操作,以将GOOGLE_APPLICATION_CREDENTIALS设置为环境变量。
我做了几次尝试(我使用的是Mac):
export GOOGLE_APPLICATION_CREDENTIALS=path/to/my.json
Run Code Online (Sandbox Code Playgroud)
不起作用
推杆
export GOOGLE_APPLICATION_CREDENTIALS=path/to/my.json
Run Code Online (Sandbox Code Playgroud)
在.bash_profile中
不起作用
在我的Java代码中:
System.setProperty("GOOGLE_APPLICATION_CREDENTIALS", "/path/to/my.json");
GoogleCredential credential = GoogleCredential.getApplicationDefault();
Run Code Online (Sandbox Code Playgroud)
不起作用
String jsonPath = "/path/to/my.json";
GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream(jsonPath));
Storage storage = StorageOptions.newBuilder().setCredentials(credentials).build().getService();
Run Code Online (Sandbox Code Playgroud)
不起作用
通过“ Maven构建>环境>新变量”将GOOGLE_APPLICATION_CREDENTIALS作为Eclipse中的环境变量,然后重新启动IDE
不起作用
总是发生相同的错误:
An error occurred during Dialogflow http request: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining …
Run Code Online (Sandbox Code Playgroud) 我需要一些提示才能了解如何使用 x509 证书针对 Keycloak 执行客户端身份验证。
我们有一个简单的 Spring Boot Web 应用程序(API REST)到 Kubernetes 集群中。该 Web 应用程序通过 API 网关(大使)公开,目前通过浏览器重定向到 Keycloak 登录页面进行保护,用户可以在其中输入用户名和密码。
然而这不是我们想要的。我们需要的是客户端身份验证(React Native 移动应用程序),其中:
不幸的是,我无法理解如何使用用户数据(信息、角色等)生成有效且可信的 x509 证书,以便从 IdP 获取访问令牌。
而且...IdP 如何检查和验证此客户端证书?是否需要在 Keycloak 上安装对应的服务器证书?
将客户端证书传递给 keycloak 的正确形式是什么(例如 CURL)?是否还需要传递私钥?为什么?
我在 Spring Boot 中有一个简单的(dockerized)Web 应用程序。
该应用程序编译正确。容器构建良好,没有错误。该应用程序在 localhost:8080 上运行良好,这是一个简单的“Hello World”。
现在,我尝试使用远程调试将 Spring Tool Suite 调试器附加到容器化 JVM,但没有成功。
故障信息是
Failed to connect to remote VM com.sun.jdi.connect.spi.ClosedConnectionException
Run Code Online (Sandbox Code Playgroud)
这是我的 Dockerfile:
FROM openjdk:8-alpine
WORKDIR /
EXPOSE 8080 8000
COPY target /
Run Code Online (Sandbox Code Playgroud)
这是我的 docker-compose.yml
version: '3.7'
services:
web:
build: .
ports:
- "8080:8080"
- "8000:8000"
command: java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=127.0.0.1:8000 -jar gs-spring-boot-docker-0.1.0.jar
Run Code Online (Sandbox Code Playgroud)
在 Spring Tool Suite 中,我有以下用于远程调试的设置:
Remote Java Application
- Connection type: Standard (Socket attach)
- Host: localhost
- port: 8000
Run Code Online (Sandbox Code Playgroud)
我使用的是 Macbook Pro 和 OSX Mojave (10.14.6) …
我有一个使用 Thymeleaf 作为视图层的 Spring Boot Web 应用程序,我需要显示一些具有特定时区的日期 (CET = UTC+1/UTC+2)。
服务器设置为 UTC,所有日期也以 UTC 格式作为日期时间存储在我的数据库中,这很好。
现在我想使用 Thymeleaf Temporals 在 HTML 页面上显示此日期,不是以 UTC 格式,而是以 CET 格式,但它似乎不起作用。
日期对象是一个 Java Instant。
从数据库检索的日期是(例如)2021-02-17T16:18:21Z
并且显示如下:
<div th:text="${#temporals.format(user.lastAccess, 'dd/MM/yyyy HH:mm')}"></div>
=> 17/02/2021 16:18
Run Code Online (Sandbox Code Playgroud)
但我想像这样展示它:
17/02/2021 17:18
Run Code Online (Sandbox Code Playgroud)
所以我用了:
或者
<div th:text="${#temporals.format(user.lastAccess, 'dd/MM/yyyy HH:mm', new java.util.Locale('it', 'IT'))}"></div>
Run Code Online (Sandbox Code Playgroud)
但日期始终显示为 UTC
17/02/2021 16:18
Run Code Online (Sandbox Code Playgroud)
Thymeleaf 的配置Java8TimeDialect
正确。
我在用着:
Spring Boot 2.2.4
Thymeleaf 3.0.11.RELEASE
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
谢谢。
java ×2
spring ×2
spring-boot ×2
ambassador ×1
datetime ×1
docker ×1
gcloud-java ×1
java-time ×1
keycloak ×1
logback ×1
logging ×1
thymeleaf ×1
timezone ×1