我该如何在Java Spring Boot中不尝试启动数据库连接?
我需要知道Java Spring引导中是否有一种方法不尝试在启动时尝试连接。我要做的是集成的SQL Server连接。我正在尝试生成具有集成连接的.jar,而不是使用SQL凭据。作为开发人员,我没有数据库的访问权限,但是运行.jar的服务帐户确实可以。 问题是,如果我尝试建立具有集成身份验证的连接字符串,它将尝试使用我的凭据登录,并且永远无法登录,因此它将无法生成.jar 目前,我的应用程序可以使用SQL凭据正常工作,但是我需要迁移到集成的凭据。
我的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.6.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>X</groupId>
<artifactId>X</artifactId>
<version>1.0.0</version>
<name>X</name>
<description>X</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
<version>0.0.20131108.vaadin1</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
和我的应用程序
spring.datasource.url=jdbc:sqlserver://X.X.X.X:1433;database=X
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.username=X
spring.datasource.password=X
server.port=8080
。
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
I need to know if there is a way in Java Spring boot not to try a connection at startup. What I am trying to do is an integrated SQL server connection. I am trying to generate a .jar with integrated connection and not with SQL credentials. As a developer, I don't have access permissions to the database, but the service account that runs the .jar does.
The thing is that if I try to establish a connection string with integrated authentication it will try to log in with my credentials and it will never be able to, so it will not be able to generate the .jar
At the moment my app is working fine with sql credentials, but I need to migrate to integrated credentials.
My pom.xml looks like this:
<?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.6.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>X</groupId>
<artifactId>X</artifactId>
<version>1.0.0</version>
<name>X</name>
<description>X</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
<version>0.0.20131108.vaadin1</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
And my application.properties:
spring.datasource.url=jdbc:sqlserver://X.X.X.X:1433;database=X
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.username=X
spring.datasource.password=X
server.port=8080
I also try adding this line in application.properties with no success:
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在主类上使用这种毒管解决所有问题
而不是
Using this anotation on the main class resolve everything
Instead of
启动JAR时,服务帐户是否使用特殊的春季配置文件?
然后,您可以在您的应用程序中执行此操作。Properties:
服务将像这样启动JAR:
Is the service account useing a special spring profile when starting the jar?
Then you could do this in you application.properties:
The service would start the jar like this: