20.03.24 15:57 작성
·
5.9K
0
안녕하세요.
로컬에 postgresql이 없어서 도커로 다운로드 받아 사용하고 있습니다. 강의에 나온것 처럼 의존성도 추가하고
postgreSQL 설치및 서버 실행을 했습니다. 그리고 스프링 부트를 실행하는데 에러가 발생하네요.ㅜㅜ
org.postgresql.util.PSQLException: Connection to localhost:5431 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
그래서 다른 사람들이 올리신 질문글들을 참조해서 수정도 해봤습니다. postgresql의 포트번호도 바꿔보고, 버전도 바꿔보았습니다. 하지만 에러는 해결되지 않더라구요. 혹시몰라 도커에서 쿼리를 만들어실행해 봤습니다. 도커에서는 문제없이 쿼리가 실행되는 것을 확인할 수 있었습니다. 재부팅도 해봤는데 소용이 없네요 ㅜㅜ 분명 뭔가 실수한것 같은데...
해결 될때까지 당분간은 mysql로 수업들어야 할 것 같네요ㅜㅜ
*환경은 이클립스 사용하고 있습니다.
답변 10
0
0
2020. 10. 14. 23:13
보시는지 모르겠지만.... 제가 윈7을 쓰거든여 근데 윈7은 도커를 사용하는데 많이 불편하더라구요.
윈7에서는 도커를 192.머시기로 다시 접근을 해야되는걸로 알고 있어여.
즉, localhost로 접근이 불가하는 이야기죠. (물론 제가 못찾아서 그럴수 는 있게다만..)
그래서 결국은 도커를 사용할때 192.머시기 ip로 접근을 해야하더라구요.
그래서 도커의 기능을 온전히 사용히 안되기 때문에 위같은 문제가 발생했다고 생각합니다.ㅎ
0
0
0
2020. 03. 26. 12:58
흠.. 도커가 안된다면 그냥 PostgreSQL을 따로 설치하셔도 되요. MySQL 설치하는거랑 크게 다르지 않습니다. 인스톨러를 제공해주니까요.
0
2020. 03. 26. 09:08
다른것도 해봤는데여.. (몽고db)그것도 안되는 걸로 봐서 도커 컨테이너가 통신을 못하고 있는 것 같더라구요. 오류도 확인 해봤는데 도커를 키지 않는 상태에서도 (도커안에 아무것도 없는 상태에서도) 똑같은 오류가 발생하더라구요. 현재 Docker Quickstart Terminal (Docker toolbox)를 사용하고 있습니다. 기선님이 알려주는 방법도 해보겠습니다.
0
2020. 03. 25. 12:52
흠.. 이상하네요. 포트 맵핑 잘 해서 도커 컨테이너 띄우신거 같고, 그 안에도 들어가진거 같은데.. 도커 컨테이너를 띄우실 때 포트 맵핑을 15432:5432 로 해보시고, jdbc 설정에서 포트도 15432 로 바꿔서 해보시겠어요?
0
2020. 03. 25. 08:56
도커에서는 강의에서 나온것처럼 똑같이 작성했습니다.
application.properties에서는
spring.datasource.hikari.maximum-pool-size=4
spring.datasource.url=jdbc:postgresql://localhost/springboot
spring.datasource.username=keesun
spring.datasource.password=pass
라고 작성했습니다.
자바소스도
@Component
public class PsSQLRunner implements ApplicationRunner {
@Autowired
private DataSource dataSource;
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public void run(ApplicationArguments args) throws Exception {
try(Connection connection = dataSource.getConnection()) {
System.out.println(connection.getMetaData().getDriverName());
System.out.println(connection.getMetaData().getURL());
System.out.println(connection.getMetaData().getUserName());
Statement statement = connection.createStatement();
String sql = "CREATE TABLE account (id INTEGER NOT NULL, name VARCHAR(555), PRIMARY KEY(id))";
statement.executeUpdate(sql);
}
jdbcTemplate.execute("INSERT INTO account VALUES (2,'klom')");
}
}
이런식으로 작성했습니다.
오류를 자세하게 보여드리지면
org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:284) ~[postgresql-42.2.10.jar:42.2.10]
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) ~[postgresql-42.2.10.jar:42.2.10]
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:211) ~[postgresql-42.2.10.jar:42.2.10]
at org.postgresql.Driver.makeConnection(Driver.java:459) ~[postgresql-42.2.10.jar:42.2.10]
at org.postgresql.Driver.connect(Driver.java:261) ~[postgresql-42.2.10.jar:42.2.10]
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467) [HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541) [HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) [HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) [HikariCP-3.2.0.jar:na]
at com.klom.inflrean.PsSQLRunner.run(PsSQLRunner.java:26) [classes/:na]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:772) [spring-boot-2.1.13.RELEASE.jar:2.1.13.RELEASE]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:762) [spring-boot-2.1.13.RELEASE.jar:2.1.13.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:319) [spring-boot-2.1.13.RELEASE.jar:2.1.13.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.1.13.RELEASE.jar:2.1.13.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204) [spring-boot-2.1.13.RELEASE.jar:2.1.13.RELEASE]
at com.klom.inflrean.SpringBootPractice4Application.main(SpringBootPractice4Application.java:10) [classes/:na]
Caused by: java.net.ConnectException: Connection refused: connect
at java.base/java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[na:na]
at java.base/java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:400) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:243) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:225) ~[na:na]
at java.base/java.net.PlainSocketImpl.connect(PlainSocketImpl.java:148) ~[na:na]
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:402) ~[na:na]
at java.base/java.net.Socket.connect(Socket.java:591) ~[na:na]
at org.postgresql.core.PGStream.<init>(PGStream.java:81) ~[postgresql-42.2.10.jar:42.2.10]
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:92) ~[postgresql-42.2.10.jar:42.2.10]
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:196) ~[postgresql-42.2.10.jar:42.2.10]
... 18 common frames omitted
2020-03-25 08:42:52.133 INFO 12428 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-25 08:42:52.153 ERROR 12428 --- [ main] o.s.boot.SpringApplication : Application run failed
java.lang.IllegalStateException: Failed to execute ApplicationRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:775) [spring-boot-2.1.13.RELEASE.jar:2.1.13.RELEASE]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:762) [spring-boot-2.1.13.RELEASE.jar:2.1.13.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:319) [spring-boot-2.1.13.RELEASE.jar:2.1.13.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.1.13.RELEASE.jar:2.1.13.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204) [spring-boot-2.1.13.RELEASE.jar:2.1.13.RELEASE]
at com.klom.inflrean.SpringBootPractice4Application.main(SpringBootPractice4Application.java:10) [classes/:na]
Caused by: org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:284) ~[postgresql-42.2.10.jar:42.2.10]
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) ~[postgresql-42.2.10.jar:42.2.10]
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:211) ~[postgresql-42.2.10.jar:42.2.10]
at org.postgresql.Driver.makeConnection(Driver.java:459) ~[postgresql-42.2.10.jar:42.2.10]
at org.postgresql.Driver.connect(Driver.java:261) ~[postgresql-42.2.10.jar:42.2.10]
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-3.2.0.jar:na]
at com.klom.inflrean.PsSQLRunner.run(PsSQLRunner.java:26) ~[classes/:na]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:772) [spring-boot-2.1.13.RELEASE.jar:2.1.13.RELEASE]
... 5 common frames omitted
Caused by: java.net.ConnectException: Connection refused: connect
at java.base/java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[na:na]
at java.base/java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:400) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:243) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:225) ~[na:na]
at java.base/java.net.PlainSocketImpl.connect(PlainSocketImpl.java:148) ~[na:na]
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:402) ~[na:na]
at java.base/java.net.Socket.connect(Socket.java:591) ~[na:na]
at org.postgresql.core.PGStream.<init>(PGStream.java:81) ~[postgresql-42.2.10.jar:42.2.10]
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:92) ~[postgresql-42.2.10.jar:42.2.10]
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:196) ~[postgresql-42.2.10.jar:42.2.10]
... 18 common frames omitted
2020-03-25 08:42:52.160 INFO 12428 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
입니다.
port를 5431로 변경해도 오류는 같았습니다.
0