国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Exécution de docker-compose avec MySQL dans SpringBoot?: base de données non connectée à l'application Spring
P粉323224129
P粉323224129 2023-08-30 12:33:00
0
1
775
<p>我在 SpringBoot 中有一個(gè)微服務(wù)(產(chǎn)品服務(wù)),在 MySQL 中有一個(gè)數(shù)據(jù)庫,并且希望在 Docker 中運(yùn)行我的應(yīng)用程序</p> <p>我可以在本地運(yùn)行該服務(wù),沒有任何錯(cuò)誤。但是當(dāng)我啟動(dòng) Docker (docker-compose up --build) 時(shí),它顯示了一些連接錯(cuò)誤。</p> <p>我在 application.properties、Dockerfile、docker-compose、pom.xml 和錯(cuò)誤中顯示了我的代碼。經(jīng)過一番修改和詢問朋友,錯(cuò)誤依然存在。如果有人能幫助我,我將不勝感激:)</p> <p>在 MySQL Workbench 中,我設(shè)置了一個(gè)與 URL <code>localhost:3306</code> 的連接,并在其中創(chuàng)建了一個(gè) <code>testdb</code> 模式。</p> <p>這是我的<code>application.properties</code></p> <pre class="brush:php;toolbar:false;">spring.datasource.url= jdbc:mysql://localhost:3306/testdb spring.datasource.username= abc spring.datasource.password= def spring.jpa.show-sql=true spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.MySQL5InnoDBDialect #Hibernate ddl auto (create, create-drop, validate, update) spring.jpa.hibernate.ddl-auto= update</pre> <p>這是 Dockerfile</p> <pre class="brush:php;toolbar:false;">FROM maven:3.8.3-openjdk-17 AS build WORKDIR /app COPY mvnw . COPY .mvn .mvn COPY pom.xml . COPY src src RUN mvn install -DskipTests RUN mkdir -p target/dependency &amp;&amp; (cd target/dependency; jar -xf ../*.jar) FROM openjdk:17-jdk-slim VOLUME /tmp ARG DEPENDENCY=/app/target/dependency COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app ENTRYPOINT [&quot;java&quot;,&quot;-cp&quot;,&quot;app:app/lib/*&quot;,&quot;com.example.helloworld.EcommerceApplication&quot;] EXPOSE 8080</pre> <p>這是 docker-compose.yml</p> <pre class="lang-yaml prettyprint-override"><code>version: &quot;3.9&quot; services: product-service: container_name: product-service build: context: . dockerfile: Dockerfile links: - database depends_on: - database environment: - SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/testdb #- SPRING_DATASOURCE_USERNAME=abc #- SPRING_DATASOURCE_PASSWORD=def - SPRING_JPA_PROPERTIES_HIBERNATE_DIALECT=org.hibernate.dialect.MySQL5InnoDBDialect - SPRING_JPA_HIBERNATE_DDL-AUTO=update - SPRING_JPA_SHOW-SQL= true ports: - 8080:8080 networks: - internal database: platform: linux/x86_64 image: mysql:8.0 container_name: mysql #ports: # - &quot;3306:3307&quot; environment: MYSQL_DATABASE: testdb MYSQL_ROOT_USER: abc MYSQL_ROOT_PASSWORD: def networks: - internal networks: internal: name: internal </code></pre> <p>這是我在 pom.xml 中的依賴項(xiàng)</p> <pre class="lang-xml prettyprint-override"><code> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.30</version> <scope>runtime</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.24</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>6.0.5</version> </dependency> <dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-ui</artifactId> <version>1.6.12</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.hibernate.validator</groupId> <artifactId>hibernate-validator</artifactId> <version>8.0.0.Final</version> </dependency> <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.3.1</version> </dependency> <dependency> <groupId>org.javassist</groupId> <artifactId>javassist</artifactId> <version>3.25.0-GA</version> </dependency> </dependencies> </code></pre> <p>我總結(jié)了這些代碼中的錯(cuò)誤</p> <p><code>產(chǎn)品服務(wù) |引起原因:com.mysql.cj.exceptions.CJCommunicationsException:通信鏈路故障</code></p> <pre class="brush:php;toolbar:false;">`product-service | Caused by: java.net.ConnectException: Connection refused` `product-service | 2023-03-14 08:45:26.585 WARN 1 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/a utoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution` `product-service | org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/b oot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution` `product-service | Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution ` `product-service | Caused by: org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution ` `product-service | 2023-03-14 08:50:17.188 ERROR 1 --- [ main] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution ` `product-service | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. `</pre> <p>產(chǎn)品服務(wù) | ...省略52個(gè)常見框架</p>
P粉323224129
P粉323224129

répondre à tous(1)
P粉722409996

Dans le fichier docker-compose, votre conteneur de base de données est nommé database et le même nom doit être utilisé comme nom d'h?te lors de l'accès à ce conteneur sur le réseau

spring.datasource.url= jdbc:mysql://database:3306/testdb
and
SPRING_DATASOURCE_URL=jdbc:mysql://database:3306/testdb

au lieu de

spring.datasource.url= jdbc:mysql://localhost:3306/testdb
and 
SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/testdb
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal