Spring Boot Project Jar文件不读取放置在类路径上的文件 [英] Spring Boot Project Jar file not reading File placed on classpath

查看:91
本文介绍了Spring Boot Project Jar文件不读取放置在类路径上的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将我的Spring Boot应用程序与Google Cloud Sql连接,并且通过将凭据文件放置在 src/main/resources 中但未连接问题>在我尝试运行Jar文件-[FileNotFound]

I am connecting my Spring Boot app with Google Cloud Sql and it got connected by placing Credential File in src/main/resources but Issue comes when I try to run the Jar File - [FileNotFound]

:: Spring Boot ::(v2.0.3.RELEASE)

application.properties-

spring.cloud.gcp.credentials.location=classpath:ArpanShoppingApp-863d536d1f93.json

运行中的jar文件出现异常

and running jar file gives exception

java -jar CloudSQLConnect-1.0.jar

例外-

2018-06-22 10:46:38.393  INFO 1172 --- [           main] o.s.c.g.s.a.GcpCloudSqlAutoConfiguration : Default MYSQL JdbcUrl provider. Connecting to jdbc:mysql://google/google_sql?cloudSqlInstance=mindful-highway-207309:asia-south1:shopping-db&socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false with driver com.mysql.jdbc.Driver
2018-06-22 10:46:38.401  INFO 1172 --- [           main] o.s.c.g.s.a.GcpCloudSqlAutoConfiguration : Error reading Cloud SQL credentials file.

java.io.FileNotFoundException: class path resource [ArpanShoppingApp-863d536d1f93.json] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/Users/arpan/Documents/workspace-sts-3.8.4.RELEASE/CloudSQLConnect/target/CloudSQLConnect-1.0.jar!/BOOT-INF/classes!/ArpanShoppingApp-863d536d1f93.json
at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:217) ~[spring-core-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:133) ~[spring-core-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
at org.springframework.cloud.gcp.sql.autoconfig.GcpCloudSqlAutoConfiguration.setCredentialsProperty(GcpCloudSqlAutoConfiguration.java:167) [spring-cloud-gcp-starter-sql-1.0.0.M1.jar!/:1.0.0.M1]
at org.springframework.cloud.gcp.sql.autoconfig.GcpCloudSqlAutoConfiguration.defaultJdbcInfoProvider(GcpCloudSqlAutoConfiguration.java:107) [spring-cloud-gcp-starter-sql-1.0.0.M1.jar!/:1.0.0.M1]
at org.springframework.cloud.gcp.sql.autoconfig.GcpCloudSqlAutoConfiguration$$EnhancerBySpringCGLIB$$edf77794.CGLIB$defaultJdbcInfoProvider$1(<generated>) [spring-cloud-gcp-starter-sql-1.0.0.M1.jar!/:1.0.0.M1]

推荐答案

这似乎是spring-cloud-gcp的限制.凭证文件似乎必须位于文件系统上,并且不能打包到jar中.最新代码具有

This appears to be a limitation of spring-cloud-gcp. It seems like credential files must be on the filesystem and cannot be package into a jar. The latest code has a better error message than the M1 version that you're using.

这篇关于Spring Boot Project Jar文件不读取放置在类路径上的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆