Google App Engine Spring Boot给出404错误



在将Spring Boot应用程序部署到Google App Engine时,我在尝试访问web应用程序时收到404错误。该应用程序在本地运行良好,但拒绝在应用程序引擎上工作。我使用命令mvn package appengine:deploy -Dapp.deploy.projectId=pollog部署应用程序。

部署应用程序后的日志如下:

2021-09-04 08:49:00 default[1]  2021-09-04 08:49:00.629  INFO 10 --- [           main] samuelb.capripol.CapripolApplication     : Starting CapripolApplication v0.0.1-SNAPSHOT using Java 11.0.11 on localhost with PID 10 (/workspace/capripol-0.0.1-SNAPSHOT.jar started by www-data in /workspace)
2021-09-04 08:49:00 default[1]  2021-09-04 08:49:00.635  INFO 10 --- [           main] samuelb.capripol.CapripolApplication     : The following profiles are active: mysql
2021-09-04 08:49:02 default[1]  2021-09-04 08:49:02.204  INFO 10 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-09-04 08:49:02 default[1]  2021-09-04 08:49:02.358  INFO 10 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 140 ms. Found 9 JPA repository interfaces.
2021-09-04 08:49:03 default[1]  2021-09-04 08:49:03.259  INFO 10 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-09-04 08:49:03 default[1]  2021-09-04 08:49:03.275  INFO 10 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-09-04 08:49:03 default[1]  2021-09-04 08:49:03.275  INFO 10 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.46]
2021-09-04 08:49:03 default[1]  2021-09-04 08:49:03.898  INFO 10 --- [           main] org.apache.jasper.servlet.TldScanner     : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2021-09-04 08:49:04 default[1]  2021-09-04 08:49:04.190  INFO 10 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-09-04 08:49:04 default[1]  2021-09-04 08:49:04.190  INFO 10 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3475 ms
2021-09-04 08:49:04 default[1]  2021-09-04 08:49:04.561  WARN 10 --- [           main] o.s.h.c.j.Jackson2ObjectMapperBuilder    : For Jackson Kotlin classes support please add "com.fasterxml.jackson.module:jackson-module-kotlin" to the classpath
2021-09-04 08:49:04 default[1]  2021-09-04 08:49:04.663  INFO 10 --- [           main] o.s.c.g.a.s.GcpCloudSqlAutoConfiguration : Default MYSQL JdbcUrl provider. Connecting to jdbc:mysql://google/pollog?cloudSqlInstance=pollog:australia-southeast1:prod-instance&socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false with driver com.mysql.jdbc.Driver
2021-09-04 08:49:04 default[1]  2021-09-04 08:49:04.677  WARN 10 --- [           main] o.s.c.g.a.s.GcpCloudSqlAutoConfiguration : spring.datasource.username is not specified. Setting default username.
2021-09-04 08:49:04 default[1]  Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
2021-09-04 08:49:04 default[1]  2021-09-04 08:49:04.877  INFO 10 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-09-04 08:49:04 default[1]  2021-09-04 08:49:04.995  INFO 10 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.31.Final
2021-09-04 08:49:05 default[1]  2021-09-04 08:49:05.246  INFO 10 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-09-04 08:49:05 default[1]  2021-09-04 08:49:05.426  INFO 10 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2021-09-04 08:49:05 default[1]  2021-09-04 08:49:05.432  WARN 10 --- [           main] com.zaxxer.hikari.util.DriverDataSource  : Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation.
2021-09-04 08:49:05 default[1]  2021-09-04 08:49:05.576  INFO 10 --- [           main] c.google.cloud.sql.mysql.SocketFactory   : Connecting to Cloud SQL instance [pollog:australia-southeast1:prod-instance].
2021-09-04 08:49:05 default[1]  2021-09-04 08:49:05.576  INFO 10 --- [           main] c.google.cloud.sql.mysql.SocketFactory   : Using GAE Unix Sockets
2021-09-04 08:49:06 default[1]  2021-09-04 08:49:06.660  INFO 10 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2021-09-04 08:49:06 default[1]  2021-09-04 08:49:06.716  INFO 10 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL57Dialect
2021-09-04 08:49:06 default[1]  2021-09-04 08:49:06.762  INFO 10 --- [onnection adder] c.google.cloud.sql.mysql.SocketFactory   : Connecting to Cloud SQL instance [pollog:australia-southeast1:prod-instance].
2021-09-04 08:49:06 default[1]  2021-09-04 08:49:06.763  INFO 10 --- [onnection adder] c.google.cloud.sql.mysql.SocketFactory   : Using GAE Unix Sockets
2021-09-04 08:49:06 default[1]  2021-09-04 08:49:06.791  INFO 10 --- [onnection adder] c.google.cloud.sql.mysql.SocketFactory   : Connecting to Cloud SQL instance [pollog:australia-southeast1:prod-instance].
2021-09-04 08:49:06 default[1]  2021-09-04 08:49:06.791  INFO 10 --- [onnection adder] c.google.cloud.sql.mysql.SocketFactory   : Using GAE Unix Sockets
2021-09-04 08:49:06 default[1]  2021-09-04 08:49:06.812  INFO 10 --- [onnection adder] c.google.cloud.sql.mysql.SocketFactory   : Connecting to Cloud SQL instance [pollog:australia-southeast1:prod-instance].
2021-09-04 08:49:06 default[1]  2021-09-04 08:49:06.812  INFO 10 --- [onnection adder] c.google.cloud.sql.mysql.SocketFactory   : Using GAE Unix Sockets
2021-09-04 08:49:06 default[1]  2021-09-04 08:49:06.840  INFO 10 --- [onnection adder] c.google.cloud.sql.mysql.SocketFactory   : Connecting to Cloud SQL instance [pollog:australia-southeast1:prod-instance].
2021-09-04 08:49:06 default[1]  2021-09-04 08:49:06.840  INFO 10 --- [onnection adder] c.google.cloud.sql.mysql.SocketFactory   : Using GAE Unix Sockets
2021-09-04 08:49:06 default[1]  2021-09-04 08:49:06.859  INFO 10 --- [onnection adder] c.google.cloud.sql.mysql.SocketFactory   : Connecting to Cloud SQL instance [pollog:australia-southeast1:prod-instance].
2021-09-04 08:49:06 default[1]  2021-09-04 08:49:06.859  INFO 10 --- [onnection adder] c.google.cloud.sql.mysql.SocketFactory   : Using GAE Unix Sockets
2021-09-04 08:49:06 default[1]  2021-09-04 08:49:06.882  INFO 10 --- [onnection adder] c.google.cloud.sql.mysql.SocketFactory   : Connecting to Cloud SQL instance [pollog:australia-southeast1:prod-instance].
2021-09-04 08:49:06 default[1]  2021-09-04 08:49:06.882  INFO 10 --- [onnection adder] c.google.cloud.sql.mysql.SocketFactory   : Using GAE Unix Sockets
2021-09-04 08:49:06 default[1]  2021-09-04 08:49:06.908  INFO 10 --- [onnection adder] c.google.cloud.sql.mysql.SocketFactory   : Connecting to Cloud SQL instance [pollog:australia-southeast1:prod-instance].
2021-09-04 08:49:06 default[1]  2021-09-04 08:49:06.909  INFO 10 --- [onnection adder] c.google.cloud.sql.mysql.SocketFactory   : Using GAE Unix Sockets
2021-09-04 08:49:06 default[1]  2021-09-04 08:49:06.925  INFO 10 --- [onnection adder] c.google.cloud.sql.mysql.SocketFactory   : Connecting to Cloud SQL instance [pollog:australia-southeast1:prod-instance].
2021-09-04 08:49:06 default[1]  2021-09-04 08:49:06.926  INFO 10 --- [onnection adder] c.google.cloud.sql.mysql.SocketFactory   : Using GAE Unix Sockets
2021-09-04 08:49:06 default[1]  2021-09-04 08:49:06.943  INFO 10 --- [onnection adder] c.google.cloud.sql.mysql.SocketFactory   : Connecting to Cloud SQL instance [pollog:australia-southeast1:prod-instance].
2021-09-04 08:49:06 default[1]  2021-09-04 08:49:06.944  INFO 10 --- [onnection adder] c.google.cloud.sql.mysql.SocketFactory   : Using GAE Unix Sockets
2021-09-04 08:49:08 default[1]  2021-09-04 08:49:08.151  INFO 10 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-09-04 08:49:08 default[1]  2021-09-04 08:49:08.166  INFO 10 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2021-09-04 08:49:09 default[1]  2021-09-04 08:49:09.012  WARN 10 --- [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2021-09-04 08:49:09 default[1]  2021-09-04 08:49:09.552  INFO 10 --- [           main] o.s.s.web.DefaultSecurityFilterChain     : Will secure Ant [pattern='/css/**'] with []
2021-09-04 08:49:09 default[1]  2021-09-04 08:49:09.553  INFO 10 --- [           main] o.s.s.web.DefaultSecurityFilterChain     : Will secure Ant [pattern='/js/**'] with []
2021-09-04 08:49:09 default[1]  2021-09-04 08:49:09.553  INFO 10 --- [           main] o.s.s.web.DefaultSecurityFilterChain     : Will secure Ant [pattern='/images/**'] with []
2021-09-04 08:49:09 default[1]  2021-09-04 08:49:09.874  INFO 10 --- [           main] o.s.s.web.DefaultSecurityFilterChain     : Will secure any request with [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@4cb957b8, org.springframework.security.web.context.SecurityContextPersistenceFilter@45b32dfe, org.springframework.security.web.header.HeaderWriterFilter@56846330, org.springframework.web.filter.CorsFilter@3cdc7b09, org.springframework.security.web.authentication.logout.LogoutFilter@7bdf61ad, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@4a1a256d, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@22d9ca63, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@d611f1c, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@7364eed1, org.springframework.security.web.session.SessionManagementFilter@6cfbbff7, org.springframework.security.web.access.ExceptionTranslationFilter@750a04ec, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@39dec536]
2021-09-04 08:49:10 default[1]  2021-09-04 08:49:10.173  INFO 10 --- [           main] o.s.c.g.core.DefaultCredentialsProvider  : Default credentials provider for Google Compute Engine.
2021-09-04 08:49:10 default[1]  2021-09-04 08:49:10.173  INFO 10 --- [           main] o.s.c.g.core.DefaultCredentialsProvider  : Scopes in use by default credentials: [https://www.googleapis.com/auth/pubsub, https://www.googleapis.com/auth/sqlservice.admin, https://www.googleapis.com/auth/devstorage.read_only, https://www.googleapis.com/auth/devstorage.read_write, https://www.googleapis.com/auth/trace.append, https://www.googleapis.com/auth/cloud-platform]
2021-09-04 08:49:10 default[1]  2021-09-04 08:49:10.186  INFO 10 --- [           main] o.s.c.g.a.c.GcpContextAutoConfiguration  : The default project ID is pollog
2021-09-04 08:49:10 default[1]  2021-09-04 08:49:10.372  INFO 10 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2021-09-04 08:49:10 default[1]  2021-09-04 08:49:10.383  INFO 10 --- [           main] samuelb.capripol.CapripolApplication     : Started CapripolApplication in 10.788 seconds (JVM running for 12.207)
2021-09-04 08:49:10 default[1]  2021-09-04 08:49:10.384  INFO 10 --- [           main] o.s.b.a.ApplicationAvailabilityBean      : Application availability state LivenessState changed to CORRECT
2021-09-04 08:49:10 default[1]  2021-09-04 08:49:10.387  INFO 10 --- [           main] o.s.b.a.ApplicationAvailabilityBean      : Application availability state ReadinessState changed to ACCEPTING_TRAFFIC
2021-09-04 08:49:10 default[1]  2021-09-04 08:49:10.448  INFO 10 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-09-04 08:49:10 default[1]  2021-09-04 08:49:10.448  INFO 10 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2021-09-04 08:49:10 default[1]  2021-09-04 08:49:10.450  INFO 10 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : Completed initialization in 2 ms
2021-09-04 08:49:10 default[1]  "GET /login HTTP/1.1" 404
2021-09-04 08:49:10 default[1]  "GET /favicon.ico HTTP/1.1" 302
2021-09-04 08:49:10 default[1]  "GET /login HTTP/1.1" 404
2021-09-04 08:52:32 default[1]  2021-09-04 08:52:32.255  INFO 10 --- [extShutdownHook] o.s.b.a.ApplicationAvailabilityBean      : Application availability state ReadinessState changed from ACCEPTING_TRAFFIC to REFUSING_TRAFFIC
2021-09-04 08:52:35 default[1]  {"severity": "WARNING", "message": "App is listening on port 8080. We recommend your app listen on the port defined by the PORT environment variable to take advantage of an NGINX layer on port 8080."}n

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 https://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.5.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>samuelB</groupId>
<artifactId>capripol</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Capripol</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-dependencies</artifactId>
<version>1.0.0.RC1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-sql-mysql</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter</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-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.11.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.2</version>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>2.3.5</version>
</dependency>
</dependencies>
<repositories>
<!-- Use Spring Milestone Repository -->
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>2.1.0</version>
<configuration>
<version>1</version>
<projectId>GCLOUD_CONFIG</projectId>
</configuration>
</plugin>
</plugins>
</build>
</project>

application.properties:

spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
spring.datasource.initialization-mode=always
spring.profiles.active=mysql
spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.resources.chain.strategy.content.enabled=true
spring.resources.chain.strategy.content.paths=/**

application-mysql.properties:

database=mysql
# Delete the rest of the original content of the file and replace with the following:
spring.cloud.gcp.sql.database-name=pollog
spring.cloud.gcp.sql.instance-connection-name=pollog:australia-southeast1:prod-instance
spring.datasource.password = password123
# Initialize the database since the newly created Cloud SQL database has no tables. The following flag is for Spring Boot 2.
spring.datasource.initialization-mode=always

主:

@SpringBootApplication
public class CapripolApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(CapripolApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(CapripolApplication.class);
}
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/static/", "classpath:/images/") //tells Spring the location of resources
.setCachePeriod(0);
}
}

WebSecurityConfig:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
@Autowired
DataSource dataSource;
@Autowired
private UserDetailsServiceImpl userDetailsService;
@Autowired
BCryptPasswordEncoder bCryptPasswordEncoder;
//configuring datasource
@Autowired
public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(dataSource);
}
@Bean
public BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Bean
public AuthenticationManager customAuthenticationManager() throws Exception {
return authenticationManager();
}
//Tells Spring to 'ignore' or 'not navigate' these when trying to access files under their paths
@Override
public void configure(WebSecurity web) {
web.ignoring().antMatchers("/css/**", "/js/**", "/images/**");
}

@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.cors().and().csrf().disable()
.authorizeRequests()
.antMatchers("/login").permitAll() //these permit which roles can access whaich pages, i.e. any can login
.antMatchers("/Admin").hasAnyAuthority("Admin", "Super Admin")//only admins/ superadmins can access admin page
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")//defines page used for logging in
.failureUrl("/login?error")//page for failed login
.defaultSuccessUrl("/")//page after successful login
.permitAll()
.and()
.logout()
.permitAll()
.and()
.sessionManagement()
.invalidSessionUrl("/login");
}
}

app.yaml:

runtime: java11
# entrypoint: java -Xmx64m -jar capripol-0.0.1-SNAPSHOT.jar
instance_class: F2
handlers:
- url: /.*
secure: always
redirect_http_response_code: 301
script: auto
- url: /login
secure: always
redirect_http_response_code: 301
script: auto

编辑:我尝试使用更大的实例类型F4, F4_1G,但这没有区别。我还添加了以下内容来抑制有关端口的警告,但这没有什么区别:

public static void main(String[] args) throws IOException {
SpringApplication.run(CapripolApplication.class, args);
int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "8080"));
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
// Set root URI path.
server.createContext("/", (t) -> {
byte[] response = "Hello World!".getBytes();
t.sendResponseHeaders(200, response.length);
try (OutputStream os = t.getResponseBody()) {
os.write(response);
}
});
// Create a second URI path.
server.createContext("/foo", (t) -> {
byte[] response = "Foo!".getBytes();
t.sendResponseHeaders(200, response.length);
try (OutputStream os = t.getResponseBody()) {
os.write(response);
}
});
server.start();
}

我也一直在试图解决它,发现路径或路线是错误的。试试看看邮差,看它是否有效。pd:我发现我的参数也错了。Datasource-username应该是在Google cloud上注册时创建的用户名

相关内容

  • 没有找到相关文章

最新更新