Error in .war file deploy to a docker tomcat

0

I have a Spring Boot application and for reasons related to performance and configuration I have to deploy using a Tomcat server not the default built-in version of Spring Boot. But I'm wanting to use docker containers to scale this application.

This is the structure of the project:

docker/
  api.dockerfile
  api.env
  tomcat-users.xml
docker-compose.yml

Contents of docker-compose.yml:

version: '3'

services:
  app:
    restart: always
    build:
      context: ./
      dockerfile: ./docker/api.dockerfile
      args:
        WAR_FILE: ./build/libs/the_app.war
    env_file:
      - docker/api.env
    environment:
      - APP_HOME=dev
      - SPRING_PROFILES_ACTIVE=API
    ports:
      - 9002:8080

Api.dockerfile content:

FROM tomcat:8.5-alpine

ENV CATALINA_HOME /usr/local/tomcat
ENV APP_HOME /usr/local/tomcat/webapps
ENV PATH $CATALINA_HOME/bin:$PATH
ENV PATH $CATALINA_HOME/lib:$PATH
RUN mkdir -p "$CATALINA_HOME"
RUN mkdir -p "$APP_HOME"
RUN mkdir -p "/usr/local/tomcat/endorsed"

ENV JAVA_OPTS="-Dspring.profiles.active=API -Dapp.home=dev"
ENV CATALINA_OPTS="-Djava.endorsed.dirs=${CATALINA_HOME}/endorsed/"

WORKDIR $CATALINA_HOME

ARG WAR_FILE
ADD ${WAR_FILE} $APP_HOME
COPY docker/tomcat-users.xml $CATALINA_HOME/conf/
RUN touch $APP_HOME/the_app.war
RUN touch $CATALINA_HOME/conf/tomcat-users.xml

CMD ["catalina.sh", "run"]

When I run docker-compose up --build I get this error and application does not go up:

app_1  |   .   ____          _            __ _ _
app_1  |  /\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
app_1  | ( ( )\___ | '_ | '_| | '_ \/ _' | \ \ \ \
app_1  |  \/  ___)| |_)| | | | | || (_| |  ) ) ) )
app_1  |   '  |____| .__|_| |_|_| |_\__, | / / / /
app_1  |  =========|_|==============|___/=/_/_/_/
app_1  |  :: Spring Boot ::        (v1.3.7.RELEASE)
app_1  |
app_1  | 2018-03-15 17:39:14.766 [localhost-startStop-1] INFO  b.c.d.c.init.TheAppApplication - Starting TheAppApplication on bb12d3811934 with PID 1 (/usr/local/tomcat/webapps/the_app/WEB-INF/classes started by root in /usr/local/tomcat)
app_1  | 2018-03-15 17:39:14.776 [localhost-startStop-1] INFO  b.c.d.c.init.TheAppApplication - The following profiles are active: API
app_1  | 2018-03-15 17:39:15.356 [background-preinit] INFO  o.h.validator.internal.util.Version - HV000001: Hibernate Validator 5.2.4.Final
app_1  | 2018-03-15 17:39:23.125 [localhost-startStop-1] INFO  org.hibernate.Version - HHH000412: Hibernate Core {4.3.11.Final}
app_1  | 2018-03-15 17:39:23.128 [localhost-startStop-1] INFO  org.hibernate.cfg.Environment - HHH000206: hibernate.properties not found
app_1  | 2018-03-15 17:39:23.131 [localhost-startStop-1] INFO  org.hibernate.cfg.Environment - HHH000021: Bytecode provider name : javassist
app_1  | 15-Mar-2018 17:39:23.241 SEVERE [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
app_1  |  org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/the_app]]
app_1  | at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
app_1  | at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
app_1  | at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
app_1  | at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
app_1  | at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:986)
app_1  | at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)
app_1  | at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
app_1  | at java.util.concurrent.FutureTask.run(FutureTask.java:266)
app_1  | at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
app_1  | at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
app_1  | at java.lang.Thread.run(Thread.java:748)
app_1  | Caused by: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'br.com.theapp.configuration.security.SecurityConfig': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.springframework.security.core.userdetails.UserDetailsService br.com.theapp.configuration.security.SecurityConfig.userDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myUserDetailsService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private br.com.theapp.core.repository.SolicitacaoRepository br.com.theapp.configuration.security.MyUserDetailsService.solicitacaoRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solicitacaoRepositoryImpl': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.jpa.boot.archive.spi.ArchiveException: Could not build ClassFile
app_1  | at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133)
app_1  | at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
app_1  | at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
app_1  | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:760)
app_1  | at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:360)
app_1  | at org.springframework.boot.SpringApplication.run(SpringApplication.java:306)
app_1  | at org.springframework.boot.context.web.SpringBootServletInitializer.run(SpringBootServletInitializer.java:149)
app_1  | at org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:129)
app_1  | at org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:85)
app_1  | at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169)
app_1  | at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5204)
app_1  | at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
app_1  | ... 10 more

If anyone knows how to solve this problem it will be of great help.

    
asked by anonymous 15.03.2018 / 18:46

0 answers