spring启动应用程序部署到tomcat后不从数据库接收数据

jv4diomz  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(284)

我已经创建了一个简单的spring启动应用程序,用于查询azuresqldb。我可以在本地运行所有事务,但是一旦我部署到tomcat,我的所有db事务都是空的。
当我查看日志时,我可以看到生成的sql查询,它看起来是正确的。我甚至在vscode中运行了生成的sql查询,它返回了正确的信息。
应用程序正在连接到数据库,但由于某些原因,它无法获取任何数据。我认为这是一个依赖性问题,但据我所知,一切看起来都是正确的。
我运行的是tomcat 8.5版
格雷德尔大厦

buildscript {
    ext {
        springBootVersion = '2.1.2.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'com.something'
version = '1.1'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}

war {
    manifest {
        attributes 'Main-Class': 'com.something.application'
    }
}

ext {
    set('azureVersion', '2.0.8')
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-data-rest'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'com.microsoft.azure:azure-keyvault-secrets-spring-boot-starter'
    implementation 'com.microsoft.sqlserver:mssql-jdbc:7.0.0.jre8'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: '2.1.2.RELEASE'
    implementation group: 'com.microsoft.azure', name: 'applicationinsights-web', version: '2.+'
    implementation group: 'com.microsoft.azure', name: 'applicationinsights-core', version: '2.+'
    implementation 'com.microsoft.azure:azure-spring-boot-starter'
    implementation 'org.projectlombok:lombok:1.18.4'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.security:spring-security-test'
}

dependencyManagement {
    imports {
        mavenBom "com.microsoft.azure:azure-spring-boot-bom:${azureVersion}"
    }
}

客户属性.java

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

import lombok.Data;

@Entity
@Data
public class Customer {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int c_id;
    private String username;
    private String first_name;
    private String last_name;
}

customerrepository.java文件

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.data.Customer;

@Repository
public interface CustomerRepository extends JpaRepository<Customer, Integer> {

    @Query("SELECT u FROM Customer u WHERE u.c_id = ?1")
    Customer getCustomer(int c_id);
}

数据源配置

@Bean
public DataSource dataSource() {
    return DataSourceBuilder.create().username(username).password(AzureSQLPwd).url(url)
            .driverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver").build();
}

应用程序属性

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServerDialect
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
logging.level.org.hibernate.SQL=DEBUG
spring.jpa.hibernate.ddl-auto=update
logging.level.org.springframework.web=DEBUG

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题