我有一個繼承的 Spring Boot 應用程式,它在碼頭上運行在 GAE 8 標準上。我們正在將其升級到 GAE 11 標準。
基于Java 8 和 Java 11/17 之間的差異,我們確定我們將嘗試使用捆綁服務遷移到 Java 11/17,并按照說明使用 App Engine API JAR 訪問捆綁服務。.
appengine-web.xml和pom.xml已按照上面的說明進行了更新,雖然我們沒有web.xml,但我們需要<app-engine-apis>true</app-engine-apis>
防止啟動時出現一些錯誤,因為我們之前用于<sessions-enabled>
保護執行器端點。我們還沒有使用app.yaml。
代碼中有一些發布腳本表明我應該能夠訪問執行器端點,以便在發布之前對我們的 DEV 專案進行冒煙測驗,以與我們的生產端點進行比較,例如/_ah/health
,這就是我開始驗證升級的地方。至今...
- 我可以訪問
/_ah/health
我們當前的生產版本(GAE 8)。 - 我可以
/_ah/health
在我們當前的開發版本(GAE 8)中訪問。 - 我可以在 (GAE 11,分支)之后
/_ah/health
本地訪問,Google App Engine Maven 插件(部署)http:8080
clean package appengine:run
- 我無法訪問
/_ah/health
并獲得404 錯誤:部署到 out dev 時未找到(GAE 11,分支)
我已經打開了日志。我可以看到它通過了幾個安全過濾器,但我仍然得到 404:
- WebAsyncManagerIntegrationFilter
- SecurityContextPersistenceFilter
- HeaderWriterFilter
- 過濾器
- 注銷過濾器
- 基本身份驗證過濾器
- RequestCacheAwareFilter
- SecurityContextHolderAwareRequestFilter
- 匿名身份驗證過濾器
- 會話管理過濾器
- 例外翻譯過濾器
所以我認為這與安全配置有關。
目的是允許所有其他執行器端點使用 /health 和 /health/**,但在application.yml中使用基本身份驗證(配置的用戶/通行證)保護所有其他執行器端點
任何幫助,將不勝感激。這是我認為一些有效的組態檔。筆記和日志...
- 將底層 Spring Boot 應用程式從 java 8 升級到 11 的所有必要作業(如網路上的許多文章/清單所建議的那樣)已在幾個月前完成,現在我們正在編譯到 java 11 并升級我們的 GAE 部署。
為 java 11 更新了 appengine-web.xml
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<service>my-api</service>
<runtime>java11</runtime>
<instance-class>F4</instance-class>
<app-engine-apis>true</app-engine-apis>
<!-- To allow securing actuator endpoints with a login -->
<sessions-enabled>true</sessions-enabled>
<automatic-scaling>
<min-idle-instances>1</min-idle-instances>
</automatic-scaling>
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/classes/logging.properties"/>
</system-properties>
</appengine-web-app>
應用程式.yml
# ...
management:
endpoints:
web:
# GAE Standard Runtime looks for health checks under /_ah - not sure if valid any more
base-path: /_ah
exposure:
include: env,health
health:
probes:
# This enables base-path/health/liveness and base-path/health/readiness
enabled: true
# This health check will fail on GAE Standard Runtime
diskspace:
enabled: false
spring:
security:
user:
name: foo
password: bar
roles: ADMIN
# ...
安全配置.java
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(final HttpSecurity http) throws Exception {
http
.cors().and().csrf().disable()
.authorizeRequests()
.requestMatchers(EndpointRequest.to("health")).permitAll()
.requestMatchers(EndpointRequest.toAnyEndpoint()).hasRole("ADMIN")
.antMatchers("/**").anonymous()
.and().httpBasic();
}
}
應用程式.java
@EnableWebSecurity
@SpringBootApplication
public class Application {
public static void main(final String[] args) {
SpringApplication.run(Application.class, args);
}
// ...
}
ServletInitializer.java
Public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(final SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}
uj5u.com熱心網友回復:
正如評論部分所確認的,使用 Cloud SDK 的舊作業版本(在這種情況下v371.0.0
)導致能夠再次成功訪問端點。
此外,該問題已在問題跟蹤器中報告:App Engine Standard Java 8: 404 Not Found
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/507756.html
標籤:Google Cloud Collective 弹簧靴 谷歌应用引擎 maven-3 java-11 弹簧启动执行器
上一篇:設定或配置云端點中的端點超時