간단한 Web 프로젝트를 Spring Boot로 만들었는데

이상하게 Tomcat에 War로 올리면 404 에러로 경로를 못찾는 현상이 발생했다.

 

덕분에 몇시간을 날렸는데 이유는 간단했다..

 

 

Spring Boot의 Main 클래스에 SpringBootServletInitializer를 상속받지 않아서였다.

 

일반적인 Spring Framework에서는 Web.xml에 DispatcherServlet을 등록하는 작업이 필요했다.

Servlet 3.0에서는 web.xml이 없이도 배포가 가능 해졌는데 Apache Tomcat 7부터 지원을 한다.

 

web.xml의 역할을 WebApplicationinitializer 인터페이스를 구현하여 프로그래밍으로 ServletContext를 구현할 수 있도록 바뀐것이다.

SpringBootServletInitializer는 WebApplicationinitializer의 구현체이다. 

SpringBootServletInitializer를 이용하여 WebApplicationContext를 생성하여 Servlet Context에 추가할 수 있다.

 

나 같은 경우에는 프로젝트에 web.xml도 없었고, WebApplicationinitializer를 구현한 SpringBootServletInitializer도 없었기 때문에 Tomcat에서 URL의 요청을 받아드릴수가 없었던 것이다..

 

SpringBootServletInitializer를 상속 한다는건 결국 Tomcat과 같은 Servlet Container 환경에서 Spring Boot Application을 동작 가능 하도록 Web Application Context를 구성한다는 의미이다.!

 

나와 같은 삽질은 다른 사람들은 하지 않았으면....

RHEL 기반인 CentOS7에 postgreSQL을 설치하는 포스팅이다.

 

이전에 포스팅한 LXD에 올린 Centos7 컨테이너로 진행할 예정인데 일반적인 환경과 크게 다를건 없을것 같다.

 

 

1. http://yum.postgresql.org/ 에 접속해보면 설치가능한 버전과 지원하는 OS를 확인할 수 있다.

 

2. 저장소를 설치

-> sudo yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm 

 

3. 설치가능한 패키지 검색

-> sudo yum list postgres*

 

3. PostgreSQL 9.6 버전 패키지 설치

-> sudo yum install postgresql96-server postgresql96-contrib

 

4. DB 생성

-> sudo /usr/pgsql-9.6/bin/postgresql96-setup initdb

 

5. PostgreSQL 시작

-> sudo systemctl restart postgresql-9.6

or

-> sudo service postgresql-9.6 start

 

6. 부팅시 자동 시작되게 설정

-> sudo systemctl enable postgresql-9.6 

 

 

이렇게 하면 PostgreSQL 서버를 설치하고 구동하는게 끝났다.

netstat -tnlp 명령어를 쳐서 아래와 같이 5432 포트로 서버가 구동되어있는걸 확인하면 끝.


[root@vm1 data]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      309/sshd
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      427/postmaster
tcp6       0      0 :::22                   :::*                    LISTEN      309/sshd
tcp6       0      0 :::5432                 :::*                    LISTEN      427/postmaster

 

접속 해보고 싶다면 psql 명령어를 이용해서 접속할 수 있다.

-> sudo -u postgres psql

참고로 psql 접속 종료 명령어는 \q

 

이제 생성한 DB를 외부에서도 접속 가능하게 설정을 수정해줘야 하는데 vi에디터로 몇 줄 고쳐주면 된다.

 

6. 외부접속 허용하기 

-> cd /var/lib/pgsql/9.6/data/

-> vi pg_hba.conf

 

스크린샷처럼 맨 하단 라인에 아래의 내용을 추가한다

 host    all     all     0.0.0.0/0       password

 

그리고서 저장 후 vi를 종료 (:wq)

 

이제 마지막으로 postgresql.conf 파일을 수정

-> vi postgresql.conf

? 명령어를 사용해서 listen 검색 후 listen_addresses = '*' 로 수정한다. (주석 제거)

 

마찬가지로 저장 후 vi 종료

 

 

Orange Ade로 리눅스에 올린 PostgreSQL을 접속해보니 잘된다. 

 

혹시 위의 설정까지 했는데 안된다면 리눅스의 방화벽을 해제하길..!!

+ Recent posts