相关疑难解决方法(0)

Spring-Boot无法在WAR文件中查找JSP页面

运行spring-boot项目(java -jar /path/to/war.war)时,找不到.jsp文件.

使用@ResponseBody注释的方法可以正常工作.视图解析器提供了JSP页面的正确路径,但找不到它们.该项目有一个配置类,没有web.xml.

配置类:

@Configuration
@EnableAutoConfiguration
@EnableWebMvc
@ComponentScan (basePackages = "org.ghc.security.web")
class ScMain extends WebMvcConfigurerAdapter {


    // SpringBoot BootStrap...
    static void main (String[] args) {
        ApplicationContext ctx = SpringApplication.run (ScMain, args)

        System.out.println("Let's inspect the beans provided by Spring Boot:");

        String[] beanNames = ctx.getBeanDefinitionNames();
        Arrays.sort(beanNames);
        beanNames.each { beanName ->
            System.out.println(beanName);
        }
    }


    @Bean
    InternalResourceViewResolver internalResourceViewResolver () {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver()
        viewResolver.setPrefix("/WEB-INF/jsp/")
        viewResolver.setSuffix(".jsp")
        viewResolver
    }
}
Run Code Online (Sandbox Code Playgroud)

调节器

@Controller
class Running {

    @RequestMapping ("/alive")  // This works fine
    @ResponseBody
    String …
Run Code Online (Sandbox Code Playgroud)

java groovy spring spring-mvc spring-boot

6
推荐指数
2
解决办法
2万
查看次数

标签 统计

groovy ×1

java ×1

spring ×1

spring-boot ×1

spring-mvc ×1