OCI 배포 : error. Tomcat 오류 DB 연결에 실패한 경우

new-pow·2022년 10월 27일
0

프로젝트 빌드 중 Tomcat 오류 'Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. '

❌ error!!

  • 상황 : jenkins로 프로젝트 구성 후, 첫 빌드를 시작.
    - Tomcat까지 실행에 성공하였다. 그러나 그 후 Deplying 과정에서 에러가 자꾸 났다.
  • 에러메시지
Tomcat started.
[DeployPublisher][INFO] Attempting to deploy 1 war file(s)
[DeployPublisher][INFO] Deploying /var/lib/jenkins/workspace/spring_project/target/project-0.0.1-SNAPSHOT.war to container Tomcat 9.x Remote with context /
  Redeploying [/var/lib/jenkins/workspace/spring_project/target/project-0.0.1-SNAPSHOT.war]
  Undeploying [/var/lib/jenkins/workspace/spring_project/target/project-0.0.1-SNAPSHOT.war]
  Deploying [/var/lib/jenkins/workspace/spring_project/target/project-0.0.1-SNAPSHOT.war]
ERROR: Build step failed with exception
org.codehaus.cargo.container.ContainerException: Failed to deploy [/var/lib/jenkins/workspace/spring_project/target/project-0.0.1-SNAPSHOT.war]
	at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:104)
	at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:172)
	at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:81)
	at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:167)
	at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:136)
	at hudson.FilePath.act(FilePath.java:1192)
	at hudson.FilePath.act(FilePath.java:1175)
	at hudson.plugins.deploy.CargoContainerAdapter.redeployFile(CargoContainerAdapter.java:133)
	at hudson.plugins.deploy.PasswordProtectedAdapterCargo.redeployFile(PasswordProtectedAdapterCargo.java:95)
	at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:113)
	at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:123)
	at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:80)
	at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:47)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:816)
	at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:765)
	at hudson.model.Build$BuildExecution.post2(Build.java:179)
	at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:709)
	at hudson.model.Run.execute(Run.java:1924)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
	at hudson.model.ResourceController.execute(ResourceController.java:107)
	at hudson.model.Executor.run(Executor.java:449)
Caused by: org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: The Tomcat Manager responded "FAIL - Deployed application at context path [/] but context failed to start
" instead of the expected "OK" message
	at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:721)
	at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deployImpl(TomcatManager.java:767)
	at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deploy(TomcatManager.java:312)
	at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:99)
	... 20 more
org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: The Tomcat Manager responded "FAIL - Deployed application at context path [/] but context failed to start
" instead of the expected "OK" message
	at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:721)
	at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deployImpl(TomcatManager.java:767)
	at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deploy(TomcatManager.java:312)
	at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:99)
	at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:172)
	at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:81)
	at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:167)
	at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:136)
	at hudson.FilePath.act(FilePath.java:1192)
	at hudson.FilePath.act(FilePath.java:1175)
	at hudson.plugins.deploy.CargoContainerAdapter.redeployFile(CargoContainerAdapter.java:133)
	at hudson.plugins.deploy.PasswordProtectedAdapterCargo.redeployFile(PasswordProtectedAdapterCargo.java:95)
	at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:113)
	at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:123)
	at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:80)
	at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:47)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:816)
	at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:765)
	at hudson.model.Build$BuildExecution.post2(Build.java:179)
	at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:709)
	at hudson.model.Run.execute(Run.java:1924)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
	at hudson.model.ResourceController.execute(ResourceController.java:107)
	at hudson.model.Executor.run(Executor.java:449)
Build step 'Deploy war/ear to a container' marked build as failure
Finished: FAILURE
  • 서치 해 본 결과, 해당 단계에서 tomcat 비밀번호를 틀렸다든가 하는 사례들이 몇몇 있었다. 하지만 나의 경우에는 다른 것들은 다 틀림이 없이 구성을 해놓았었다.

파악

  1. Tomcat log 파일을 뒤져보았다.
# log 파일 경로로 이동
cd /usr/local/tomcat9/logs

# 파일 열기 (이름이 다를 수 있으므로 ls로 확인하고 열자)
vi catalina.out
  1. 문제 상황 확인
***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
        If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
        If you have database settings to be loaded from a particular profile you may need to activate it (the profiles aws are currently active).
       
        ...
        (후략)
        ...
  • 위와 같은 메시지가 기록되어있다. DB와 연결이 안되었다는 뜻이며, url부터 지정해주어야 한다.
  1. 원인 보안탓에 DB 정보를 github에 올라가지 않게 막아두고, 별도의 properties에 옮겨놓았는데.. 깜빡 잊고 서버에 추가를 안했었다🥹 이게 원인이었다니 허무하다..!

해결

  1. 프로젝트 경로로 이동
# 현재 위치 파악
pwd

# 프로젝트 경로로 이동
# 위의 오류 메시지에 기록되어 있음.
cd /opc/var/lib/jenkins/workspace
  1. properties 파일 위치로 이동

  2. application.properties 파일 생성

sudo vi aplication-oci.properties

# DB 정보 입력 (mySql)
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/{스키마}?autoReconnect=true spring.datasource.username={DB ID}
spring.datasource.password={DB Pw}
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

참고

profile
저는 블로그 이사를 갔습니다

0개의 댓글