Tomcat问题:原始服务器没有找到目标资源的当前表示,或者不愿意透露存在的目标资源

时间:2018-02-18 11:19:45

标签: java spring tomcat

我有春季MVC项目。我将我的项目部署到Tomcat 9容器,但是我遇到了这个问题:

HTTP状态404 - 未找到 输入状态报告

消息/ avtonomki /

描述源服务器没有找到目标资源的当前表示,或者不愿意透露该目标资源是否存在。

Apache Tomcat / 9.0.5

我的MVC配置是:

@Configuration
@EnableWebMvc
@ComponentScan({ "ru.dev.avtonomki" })
public class WebMVCConfig extends WebMvcConfigurerAdapter implements ApplicationContextAware {

    private ApplicationContext applicationContext;

    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    @Bean
    public ViewResolver jspViewResolver() {
        ThymeleafViewResolver resolver = new ThymeleafViewResolver();
        resolver.setTemplateEngine(templateEngine(jspTemplateResolver()));
        resolver.setContentType("text/html");
        resolver.setCharacterEncoding("UTF-8");
        resolver.setOrder(1);
        resolver.setViewNames(ArrayUtil.array("*.html"));
        return resolver;
    }

    private TemplateEngine templateEngine(ITemplateResolver templateResolver) {
        SpringTemplateEngine engine = new SpringTemplateEngine();
        engine.addDialect(new LayoutDialect(new GroupingStrategy()));
        engine.addDialect(new Java8TimeDialect());
        engine.setTemplateResolver(templateResolver);
        //engine.setTemplateEngineMessageSource(messageSource());
        return engine;
    }

    private ITemplateResolver jspTemplateResolver() {
        SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
        resolver.setApplicationContext(applicationContext);
        resolver.setPrefix("/WEB-INF/templates/");
        //resolver.setSuffix(".jsp");
        resolver.setCacheable(false);
        resolver.setTemplateMode(TemplateMode.HTML5);
        return resolver;
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addFormatter(new NameFormatter());
    }
}

我的项目结构是:

src -
    | - main - 
             | - java - 
                      | - ru.dev.avtonomki
                            | - app
                            | - config
                            | - controller
                            | - dto
                            | - formatter
                            | - model
                            | - repository
                            | - service
                            | - utils
                      | -resources
                            | - js
                            | - css
                            | - application.properties
                      | - webapps
                            | - WEB-INF
                                  | - templates
                                         | - index.html

0 个答案:

没有答案