DevOps/AWS

./gradlew test 실패 원인..

어렵다어려웡 2021. 6. 11. 15:42

우선 정확한 원인이 무엇인지 몰랐으나 책을 따라서 우선 배포 스크립트를 만들어서

그대로 진행을 해봤습니다.

 

물론 배포 스크립트 과정에서 gradlew build를 해야했기 떄문에 결론적으로 똑같이 에러가 발생했으나

그 덕분에 원인을 얼추 찾게 되었습니다.

org.springframework.beans.factory.BeanDefinitionStoreException: 
Failed to parseconfiguration class [com.awse.commerce.CommerceApplication]; 
nested exception is java.io.FileNotFoundException: class path resource [application-pay.properties] 
cannot be opened because it does not exist

 

제 프로젝트는 현재 결제 API를 연동시켜 놓았고 해당 API에서 사용되는 private key 와 applicationId를

properties 파일을 만들어서 gitignore로 숨겨놓은 상태였습니다.

 

그래서 서버에서 프로젝트를 빌드하게 되면 해당 파일이 숨겨놓은 상태로 없기 때문에

읽을 수 없어서 파일을 찾을수 없다는 예외가 발생했던 것.

 

그래서 책을 따라서 서버단에 application-pay.properties 파일을 따로 생성해뒀다.

-rwxrwxrwx 1 root     root     175 Jun 10 19:00 application-pay.properties
drwxrwxr-x 3 ec2-user ec2-user  95 Jun 10 20:39 step1

 

이후 배포 스크립트에서는 깃을 pull 한 다음 해당 파일의 classpath에 파일을 복사시켰다

( -Dspring.config.location 으로 파일의 경로를 지정해서 쓸수 있겠지만 우선 했다)

// 두 스크립트 변수는 내가 지정해둔 파일경로와 프로젝트 명칭이다
cd $REPOSITORY/$PROJECT_NAME/src/main/resources

cp $PAY_FILE_PATH $PAY_FILE

 이런식으로 파일경로를 지정했다..

nohup java -jar -Dspring.config.location=classpath=application.properties\
			-Dspring.config.location=classpath=application-pay.properties\
            $REPOSITORY/$JAR_NAME 2>&1 &

 

이번에는 DB관련 설정이 없다는 에러가 나타났다.

***************************
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 (no profiles are currently active).

책을 따라서 DB관련 properties 파일들을 만들고 배포스크립트에 집어넣었다.

 

nohup java -jar -Dspring.config.location=classpath=application.properties\
			-Dspring.config.location=classpath=application-pay.properties\
            -Dspring.config.location=classpath=application-oauth.properties\
            -Dspring.config.location=classpath=application-real.properties\
            -Dspring.config.location=classpath=application-real-db.properties\
            -Dspring.profiles.active=real\
            $REPOSITORY/$JAR_NAME 2>&1 &

 

하지만 그대로 DB설정에 관한 에러는 나왔으며 profiles로 설정한 값이 real 만 나오게 되었다.

여기서 계속 삽질을 하다가 도저히 안되겠어서

직접 블로그로 들어가서 책의 예제 + pay.properties 파일을 넣어봤다.

 

nohup java -jar -Dspring.config.location=classpath:application.properties,classpath:application-pay.properties,classpath:application-real.properties,/home/ec2-user/app/application-oauth.properties,/home/ec2-user/app/application-real-db.properties\
        -Dspring.profiles.active=real\
         $REPOSITORY/$JAR_NAME 2>&1 &

 

그 결과...

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.5)

2021-06-11 15:07:06.260  INFO 4294 --- [           main] com.awse.commerce.CommerceApplication    : Starting CommerceApplication using Java 1.8.0_282 on commerce-ec2 with PID 4294 (/home/ec2-user/app/step1/commerce-0.0.1-SNAPSHOT.jar started by ec2-user in /home/ec2-user/app/step1)
2021-06-11 15:07:06.264  INFO 4294 --- [           main] com.awse.commerce.CommerceApplication    : The following profiles are active: real,oauth,real-db,pay
2021-06-11 15:07:09.602  INFO 4294 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-06-11 15:07:09.890  INFO 4294 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 273 ms. Found 7 JPA repository interfaces.
2021-06-11 15:07:12.356  INFO 4294 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-06-11 15:07:12.377  INFO 4294 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-06-11 15:07:12.378  INFO 4294 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.45]
2021-06-11 15:07:12.537  INFO 4294 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-06-11 15:07:12.537  INFO 4294 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 6067 ms
2021-06-11 15:07:13.842  INFO 4294 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-06-11 15:07:13.994  INFO 4294 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.30.Final
2021-06-11 15:07:14.324  INFO 4294 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-06-11 15:07:14.515  INFO 4294 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2021-06-11 15:07:14.641  INFO 4294 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2021-06-11 15:07:14.681  INFO 4294 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
2021-06-11 15:07:17.551  INFO 4294 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-06-11 15:07:17.569  INFO 4294 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2021-06-11 15:07:19.690  WARN 4294 --- [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
 Execute To PasswordEncoder com.awse.commerce.domains.util.config.SecurityConfig.passwordEncoder()executed.. 63
 Execute To JPAQueryFactory com.awse.commerce.domains.util.config.QuerydslConfiguration.jpaQueryFactory()executed.. 16
2021-06-11 15:07:22.182  INFO 4294 --- [           main] o.s.s.web.DefaultSecurityFilterChain     : Will secure any request with [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@367795c7, org.springframework.security.web.context.SecurityContextPersistenceFilter@253c1256, org.springframework.security.web.header.HeaderWriterFilter@77e80a5e, org.springframework.security.web.authentication.logout.LogoutFilter@49d98dc5, org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestRedirectFilter@4604b900, org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter@3961a41a, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@d4602a, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@503fbbc6, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@67fe380b, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@d2387c8, org.springframework.security.web.session.SessionManagementFilter@240139e1, org.springframework.security.web.access.ExceptionTranslationFilter@2d140a7, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@74a195a4]
 Execute To Docket com.awse.commerce.domains.util.config.SwaggerConfig.api()executed.. 31
2021-06-11 15:07:22.931  INFO 4294 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-06-11 15:07:23.082  INFO 4294 --- [           main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page: class path resource [static/index.html]
2021-06-11 15:07:23.840  INFO 4294 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2021-06-11 15:07:23.848  INFO 4294 --- [           main] d.s.w.p.DocumentationPluginsBootstrapper : Context refreshed
2021-06-11 15:07:23.884  INFO 4294 --- [           main] d.s.w.p.DocumentationPluginsBootstrapper : Found 1 custom documentation plugin(s)
2021-06-11 15:07:23.914  INFO 4294 --- [           main] s.d.s.w.s.ApiListingReferenceScanner     : Scanning for api listing references
2021-06-11 15:07:24.361  INFO 4294 --- [           main] com.awse.commerce.CommerceApplication    : Started CommerceApplication in 19.565 seconds (JVM running for 21.052)

 서버가 켜지는데 20초나 걸리는 현상이 나타났으나..

최초로 서버에서 프로젝트 구동이 완료되었다.

The following profiles are active: real,oauth,real-db,pay

profiles 활성화 또한 설정한 파일들이 전부 구동되는 상태가 되었다..

 

Dspring.config.location 설정시에 스크립트를 붙여서 써야 정상작동이 되는지 그런것에 대한 개념이 없다보니

스크립트를 다르게 작성한 나머지 시간을 꽤 썻다.

 

어렵긴 어렵다. 서버관련된 이슈들은 무조건적으로 작성해서 익혀놓는게 좋을것같다..

서버를 켜서 들어가보니 타임리프 템플릿 경로 관련 문제가 발생해서 이제 이쪽부분을 건드리면 된다..