我正在连接到 Azure SQL 数据库,下一个任务是在连接失败时创建自定义重试逻辑。我希望重试逻辑在启动时(如果需要)以及应用程序运行时出现连接失败时运行。我做了一个测试,从我的应用程序中删除了 IP 限制,然后导致我的应用程序出现异常(如例外)。我想在抛出该异常时进行处理,以便我可以触发一个作业来验证应用程序和服务器是否配置正确。我正在寻找一种可以处理这些异常并重试数据库事务的解决方案?
数据源配置
@Bean
@Primary
public DataSource dataSource() {
return DataSourceBuilder
.create()
.username("username")
.password("password")
.url("jdbc:sqlserver://contoso.database.windows.net:1433;database=*********;user=******@*******;password=*****;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;")
.driverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver")
.build();
}
Run Code Online (Sandbox Code Playgroud)
应用程序属性
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServerDialect
spring.jpa.show-sql=true
logging.level.org.springframework.web: ERROR
logging.level.org.hibernate: ERROR
spring.datasource.tomcat.max-wait=10000
spring.datasource.tomcat.max-active=1
spring.datasource.tomcat.test-on-borrow=true
spring.jpa.hibernate.ddl-auto=update
Run Code Online (Sandbox Code Playgroud) spring-data spring-data-jpa spring-retry hikaricp azure-sql-database
我一直在关注 spring 提供的教程,似乎无法理解为什么我的 .war 文件是空的。点击这里查看/下载代码。最终目标是下载此文件,构建一个 .war 文件,然后将其部署到我的 tomcat 服务器。我已将以下内容添加到 build.gradle
应用插件:“战争”
但这只会生成包含零类文件的战争。
构建.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle
plugin:1.5.3.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
// tag::actuator[]
compile("org.springframework.boot:spring-boot-starter-actuator")
// end::actuator[]
// tag::tests[]
testCompile("org.springframework.boot:spring-boot-starter-test")
// end::tests[]
}
Run Code Online (Sandbox Code Playgroud) gradle ×1
hikaricp ×1
spring ×1
spring-boot ×1
spring-data ×1
spring-retry ×1
tomcat ×1
war ×1