简体   繁体   中英

Using MySQL with Spring boot docker image

I have this problem that I can't really find a solution.

I have 1GB droplet (Ubuntu) on digitalocean and I installed mysql using this page . I logged in mysql console, imported my database, created a new user with required permissions. Its all good until this point.

I have pulled my docker image from docker hub with this line:

docker run --rm -p 80:80 my-username/image-name

It downloaded for the first time and started my Spring boot application but I got this exception every time I try to run my image.

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
....
....
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

my application.yaml file looks like this:

spring:
  mvc:
    view:
      prefix: /WEB-INF/jsp/
      suffix: .jsp
  datasource:
    url: jdbc:mysql://localhost:3306/db-name
    username: my-username
    password: secret-pwd
    driver-class-name: com.mysql.jdbc.Driver
  jpa:
    hibernate:
      dialect: org.hibernate.dialect.MySQLInnoDBDialect
    generate-ddl: true

MySQL server is up and running. What am I missing here?

EDIT:

I edited application.yaml file

spring:
  mvc:
    view:
      prefix: /WEB-INF/jsp/
      suffix: .jsp
  datasource:
    url: jdbc:mysql://localhost:3306/db-name
    username: my-username
    password: secret-pwd
    driver-class-name: com.mysql.jdbc.Driver
  jpa:
    generate-ddl: true
    database: mysql

and I was able to start the application. But when I try to open the page : I get 404 error.

There was an unexpected error (type=Not Found, status=404).
/WEB-INF/jsp/index.jsp

This seems like your docker image cannot connect to your mysql server...

To troubleshoot this you could try the following...

1) Check if you've configured mysql properly!

2) Mysql in linux based OS need to be configured with login permissions from different remote IP addresses or locations ...(As docker is self hosted in your environment. try editing the ip address that is used to access your mysql server against your user).

3)Check for every mysql user if that user can be reached from remote location. If not configure it again.

4) Check for firewall on your mysql port.

PS: I use mysql workbench to access mysql remotely and thus can give special permissions to other users i create for different operations and queries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM