개발 - WEB, WAS, DB

tomcat 환경에서 mysql JDBC 연결시 - Communications link failure

개미v 2020. 5. 13. 15:21

 

tomcat 환경에서 mysql JDBC 연결시 아래 에러가 나는 경우 해결 방법

에러 내용

com.mysql.cj.jdbc.exceptions.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.

원인

tomcat 보안설정에서 차단 되어 있음

해결방법

catalina.policy 설정 파일에 아래 권한 추가

 

permission java.net.SocketPermission "localhost:3306", "connect";

 

// ========== WEB APPLICATION PERMISSIONS =====================================
// These permissions are granted by default to all web applications
// In addition, a web application will be given a read FilePermission
// for all files and directories in its document root.
grant {

    permission java.net.SocketPermission "localhost:3306", "connect";
    
    // Required for JNDI lookup of named JDBC DataSource's and
    // javamail named MimePart DataSource used to send mail
    permission java.util.PropertyPermission "java.home", "read";
    permission java.util.PropertyPermission "java.naming.*", "read";
    permission java.util.PropertyPermission "javax.sql.*", "read";