thecrash
20
2017-10-13 10:50:10
5
5679

Spring boot gradle jar 배포 실행시 tiles3 경로 에러 문제 발생


spring boot 1.5.4.RELEASE

tiles 3.0.5

gradle 로 빌드하여 내장톰켓 jar 파일 생성 후

jar 파일 실행하면 tiles 경로를 찾지 못하는 에러가 발생합니다 

/WEB-INF/views/tiles/tiles.xml 경로를 인식하지 못하고 있습니다

문제 인가요 도움 부탁드립니다.


tiles 경로

======================================================


AppConfig.java

===============================================================

@Bean

    public TilesConfigurer tilesConfigurer() {

        TilesConfigurer tiles = new TilesConfigurer();

        tiles.setDefinitions(new String[] {"/WEB-INF/views/tiles/tiles.xml"});

        return tiles;

    }

    @Bean

    public UrlBasedViewResolver viewResolver() {

        UrlBasedViewResolver tilesViewResolver = new UrlBasedViewResolver();

        tilesViewResolver.setViewClass(TilesView.class);

        return tilesViewResolver;

    }


ERROR

===================================================================

20171013 10:23:10.732 [main] WARN o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tilesConfigurer' defined in class path resource [com/kbms/springmvc/AppConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No URL for ServletContext resource [/WEB-INF/views/tiles/tiles.xml]

20171013 10:23:10.749 [main] INFO o.a.c.c.StandardService - Stopping service [Tomcat]

20171013 10:23:10.809 [main] INFO o.s.b.a.l.AutoConfigurationReportLoggingInitializer -


Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.

20171013 10:23:10.816 [main] ERROR o.s.b.SpringApplication - Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tilesConfigurer' defined in class path resource [com/kbms/springmvc/AppConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No URL for ServletContext resource [/WEB-INF/views/tiles/tiles.xml]

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)

        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)

        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)

        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)

        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)

        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)

        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)

        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)

        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)

        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)

        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)

        at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)

        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)

        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)

        at com.kbms.KbmsApplication.main(KbmsApplication.java:28)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:498)

        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)

        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)

        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)

        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)

Caused by: java.lang.IllegalArgumentException: No URL for ServletContext resource [/WEB-INF/views/tiles/tiles.xml]

        at org.springframework.web.servlet.view.tiles3.SpringWildcardServletTilesApplicationContext.getResources(SpringWildcardServletTilesApplicationContext.java:96)

        at org.springframework.web.servlet.view.tiles3.TilesConfigurer$SpringTilesContainerFactory.getSources(TilesConfigurer.java:305)

        at org.apache.tiles.factory.BasicTilesContainerFactory.createLocaleDefinitionDao(BasicTilesContainerFactory.java:182)

        at org.apache.tiles.factory.BasicTilesContainerFactory.createDefinitionsFactory(BasicTilesContainerFactory.java:137)

        at org.springframework.web.servlet.view.tiles3.TilesConfigurer$SpringTilesContainerFactory.createDefinitionsFactory(TilesConfigurer.java:353)

        at org.apache.tiles.factory.BasicTilesContainerFactory.createContainer(BasicTilesContainerFactory.java:86)

        at org.apache.tiles.startup.AbstractTilesInitializer.createContainer(AbstractTilesInitializer.java:114)

        at org.apache.tiles.startup.AbstractTilesInitializer.initialize(AbstractTilesInitializer.java:64)

        at org.springframework.web.servlet.view.tiles3.TilesConfigurer.afterPropertiesSet(TilesConfigurer.java:271)

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)

        ... 24 common frames omitted

Caused by: java.io.FileNotFoundException: ServletContext resource [/WEB-INF/views/tiles/tiles.xml] cannot be resolved to URL because it does not exist

        at org.springframework.web.context.support.ServletContextResource.getURL(ServletContextResource.java:156)

        at org.springframework.web.servlet.view.tiles3.SpringWildcardServletTilesApplicationContext.getResources(SpringWildcardServletTilesApplicationContext.java:91)

        ... 34 common frames omitted

0
  • 답변 5

  • boostraping
    23
    2017-10-13 10:57:25 작성 2017-10-13 10:57:48 수정됨

    실행가능한 war로 export하세요

    jar로 export시 템플릿관련 파일들이 잘 안되는 문제가 있어요

    gradle프로젝트면 그래들 명령어 중에 bootRepackage라는 명령어로 실행하시면

    실행가능한 war파일 자동으로 생성해주는데 

    maven 프로젝트면 잘모르겠네요~

    비슷한거 있을꺼같은데


  • boostraping
    23
    2017-10-13 11:00:37

    그리고 실행가능한 war(embbed tomcat version)로 export하셨다면

    콘솔에서 

    java -jar 실행화일명.war 로 실행하실수 있습니다.

  • thecrash
    20
    2017-10-13 11:42:23

    답변감사합니다.

     한번 해보겠습니다.

  • thecrash
    20
    2017-10-19 14:09:31
    그냥 jar 는 포기하고 war 로 build 해서 배포 하였습니다 
  • Youjin Lee
    2
    2021-05-24 11:25:28

    실례하겠습니다..ㅠ
     위 게시물 분의 에러가 발생하였는데 boostraping 님께서 말씀해주신 해결방법을 진행하는 방법을 잘 몰라서 여쭈어 봅니다..ㅠ


    실행가능한 war로 export하세요

    jar로 export시 템플릿관련 파일들이 잘 안되는 문제가 있어요

    gradle프로젝트면 그래들 명령어 중에 bootRepackage라는 명령어로 실행하시면

    실행가능한 war파일 자동으로 생성해주는데 

    maven 프로젝트면 잘모르겠네요~

    비슷한거 있을꺼같은데

    vscode를 사용하고 있는데 어떻게 진행하면 되나요?ㅠㅠ

  • 로그인을 하시면 답변을 등록할 수 있습니다.