gpt4 book ai didi

java - Spring boot 执行没有错误,但是,没有在服务器上创建表

转载 作者:行者123 更新时间:2023-12-03 22:58:52 25 4
gpt4 key购买 nike

大部分代码都是从旧项目复制过来的,除了这次我用 Gradle 而不是 maven。
当我通过 IntelliJ 在我的本地机器上运行项目时,会创建新表并且一切正常。
但是,当我将其上传到tomcat时,我看不到数据库中的表。
当我检查端点并尝试保存新数据时,这是可能的,保存后我可以访问它们。
当项目在tomcat中时,数据是可以访问的。一旦我重新加载/取消部署并再次部署,数据就会丢失,我无法通过服务访问数据。直到我保存新数据。
也许它与“内存数据库”有关。
应用程序属性:

spring.jpa.hibernate.ddl-auto=update
spring.datasource.driverClassName=com.mysql.jdbc.Driver

spring.datasource.url=jdbc:mysql://localhost:3306/database_name?autoReconnect=true&useSSL=false&createDatabaseIfNotExist=true
spring.datasource.username=username
spring.datasource.password=password

spring.jta.enabled=true

spring.datasource.hikari.minimum-idle=10
spring.datasource.hikari.maximum-pool-size=300
spring.datasource.hikari.idleTimeout=30000
spring.datasource.hikari.maxLifetime=2000000
spring.datasource.hikari.connectionTimeout=30000
我检查了几个小时,找不到问题。
我登录到服务器并检查了 catalina 日志,没有错误消息。在 IntelliJ 创建表之前,它们或多或少是相同的,它在 Catalina.out 上丢失了。
org.hibernate.SQL : create table table_name ...
主类在 x.y 包中,实体在 x.y.database.tables 中。
从 catalina.out 登录:
30-May-2021 23:15:40.921 INFO [ajp-nio-8009-exec-356] org.apache.jasper.servlet.TldScanner.scanJars 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.
30-May-2021 23:15:41.009 INFO [ajp-nio-8009-exec-356] org.apache.catalina.core.ApplicationContext.log 2 Spring WebApplicationInitializers detected on classpath

. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.0)

2021-05-30 23:15:41.778 INFO 1454 --- [o-8009-exec-356] com.global.ServletInitializer : Starting ServletInitializer using Java 1.8.0_292 on ubuntu-droplet1 with PID 1454 (/opt/tomcat/temp/50-global##10049/WEB-INF/classes started by tomcat in /)
2021-05-30 23:15:41.782 INFO 1454 --- [o-8009-exec-356] com.global.ServletInitializer : No active profile set, falling back to default profiles: default
2021-05-30 23:15:42.051 WARN 1454 --- [kground-preinit] o.s.h.c.j.Jackson2ObjectMapperBuilder : For Jackson Kotlin classes support please add "com.fasterxml.jackson.module:jackson-module-kotlin" to the classpath
2021-05-30 23:15:43.027 INFO 1454 --- [o-8009-exec-356] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-05-30 23:15:43.150 INFO 1454 --- [o-8009-exec-356] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 105 ms. Found 1 JPA repository interfaces.
30-May-2021 23:15:43.881 INFO [ajp-nio-8009-exec-356] org.apache.catalina.core.ApplicationContext.log Initializing Spring embedded WebApplicationContext
2021-05-30 23:15:43.881 INFO 1454 --- [o-8009-exec-356] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2023 ms
2021-05-30 23:15:43.931 TRACE 1454 --- [o-8009-exec-369]
2021-05-30 23:15:44.372 INFO 1454 --- [o-8009-exec-356] com.zaxxer.hikari.HikariDataSource : HikariPool-28 - Starting...
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-05-30 23:15:44.704 INFO 1454 --- [o-8009-exec-356] com.zaxxer.hikari.HikariDataSource : HikariPool-28 - Start completed.
2021-05-30 23:15:44.796 INFO 1454 --- [o-8009-exec-356] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-05-30 23:15:44.910 INFO 1454 --- [o-8009-exec-356] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.31.Final
2021-05-30 23:15:45.199 INFO 1454 --- [o-8009-exec-356] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-05-30 23:15:45.504 INFO 1454 --- [o-8009-exec-356] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2021-05-30 23:15:46.812 INFO 1454 --- [o-8009-exec-356] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-05-30 23:15:46.829 INFO 1454 --- [o-8009-exec-356] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2021-05-30 23:15:47.884 WARN 1454 --- [o-8009-exec-356] 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-05-30 23:15:48.265 INFO 1454 --- [o-8009-exec-356] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: Ant [pattern='/**'], [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@1177a1e1, org.springframework.security.web.context.SecurityContextPersistenceFilter@3f4454d9, org.springframework.security.web.header.HeaderWriterFilter@132a4fd3, org.springframework.security.web.authentication.logout.LogoutFilter@24276bb0, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@5f273afb, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@5ef67d5b, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@7361a373, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@5e9936ce, org.springframework.security.web.session.SessionManagementFilter@3e4a0114, org.springframework.security.web.access.ExceptionTranslationFilter@14437cb5, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@1ca8217d]
2021-05-30 23:15:49.023 INFO 1454 --- [o-8009-exec-356] com.global.ServletInitializer : Started ServletInitializer in 7.871 seconds (JVM running for 24656.257)
2021-05-30 23:15:49.025 INFO 1454 --- [o-8009-exec-356] o.s.b.a.ApplicationAvailabilityBean : Application availability state LivenessState changed to CORRECT
2021-05-30 23:15:49.028 INFO 1454 --- [o-8009-exec-356] o.s.b.a.ApplicationAvailabilityBean : Application availability state ReadinessState changed to ACCEPTING_TRAFFIC
30-May-2021 23:15:49.036 INFO [ajp-nio-8009-exec-356] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/opt/tomcat/some_name/global##10049.war] has finished in [11,445] ms
30-May-2021 23:15:49.036 INFO [ajp-nio-8009-exec-356] org.apache.catalina.core.ApplicationContext.log HTMLManager: list: Listing contexts for virtual host '**domain**'
30-May-2021 23:16:01.419 INFO [ajp-nio-8009-exec-369] org.apache.catalina.core.ApplicationContext.log HTMLManager: list: Listing contexts for virtual host '**domain**'
30-May-2021 23:16:02.012 INFO [ajp-nio-8009-exec-372] org.apache.catalina.core.ApplicationContext.log HTMLManager: list: Listing contexts for virtual host '**domain**'
30-May-2021 23:16:04.502 INFO [ajp-nio-8009-exec-371] org.apache.catalina.core.ApplicationContext.log Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-05-30 23:16:04.503 INFO 1454 --- [o-8009-exec-371] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2021-05-30 23:16:04.505 INFO 1454 --- [o-8009-exec-371] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms

最佳答案

您缺少某些配置,例如 generate-dll .请尝试以下操作:

spring.datasource.url=jdbc:mysql://localhost:3306/dbName
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=username
spring.datasource.password=password
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
我使用了不同的驱动程序类,因为不推荐使用来自您的属性的驱动程序类(这与您的问题无关)。
P.S.:我同意评论 - update不应在生产中使用。我什至不会依赖 hibernate 来管理我的数据库模式,而是使用像 flyway/liquibase 这样的工具。

关于java - Spring boot 执行没有错误,但是,没有在服务器上创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67765588/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com