简体   繁体   中英

How to run spring-boot embedded tomcat with tiles in eclipse?

I have got a spring-boot application packaged as an executable warfile, supporting embedded tomcat with spring mvc, jsp and tiles.

When starting the built webapplication in a shell with java -jar app.war , I get the service running successfully. Instead, when I try to run a launch configuration inside eclipse, sprint-boot cannot complete initialization of tiles, with this exception:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tilesConfigurer' defined in class path resource [au/com/inspiredgroup/config/MvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No URL for class path resource [WEB-INF/tiles.xml]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:688)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:958)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:947)
    at au.com.inspiredgroup.Application.main(Application.java:86)
Caused by: java.lang.IllegalArgumentException: No URL for class path resource [WEB-INF/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:306)
    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:354)
    at org.apache.tiles.factory.BasicTilesContainerFactory.createContainer(BasicTilesContainerFactory.java:86)
    at org.springframework.web.servlet.view.tiles3.TilesConfigurer$SpringTilesContainerFactory.createContainer(TilesConfigurer.java:297)
    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:1625)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562)
    ... 15 more
Caused by: java.io.FileNotFoundException: class path resource [WEB-INF/tiles.xml] cannot be resolved to URL because it does not exist
    at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:187)
    at org.springframework.web.servlet.view.tiles3.SpringWildcardServletTilesApplicationContext.getResources(SpringWildcardServletTilesApplicationContext.java:91)
    ... 26 more

This is the MVC configuration:

@EnableWebMvc
@Configuration
public class MvcConfiguration extends WebMvcConfigurerAdapter {

    /**
     * Basic setup for JSP views.
     */
    @Bean(name = "viewResolver")
    public InternalResourceViewResolver configureInternalViewResolver() {
        final InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix(PREFIX);
        resolver.setSuffix(SUFFIX);
        resolver.setOrder(1);
        return resolver;
    }

    @Bean
    public TilesViewResolver tilesViewResolver() {
        final TilesViewResolver tilesViewResolver = new TilesViewResolver();
        tilesViewResolver.setOrder(0);
        return tilesViewResolver;
    }

    @Bean
    public TilesConfigurer tilesConfigurer() {
        final TilesConfigurer configurer = new TilesConfigurer();
        configurer.setDefinitions(new String[] { "classpath:/WEB-INF/tiles.xml" });
        return configurer;
    }
    [...]
}

The launcher in eclipse is configured as a plain Java Application.

This happened for an imported project, for which eclipse settings were not shared in the source control repository (understandingly, that is most often a wise thing (not-) to do in my opinion); it might have been because of that, or maybe not, anyway using the maven archetype for creating a new project does not reproduce the issue.

To fix my setup in eclipse, I had to edit the launch configuration (for running as a Java Application ), go the the classpath tab, and click "advanced...' button, then 'Add folder' and navigate to add the /src/main/webapp folder. It will be added in 'User Entries'.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM