springBoot配置视图解析 跳转jsp页面遇见错误之一

   注意spring boot 版本,版本低的要加.mvc

配置与代码:

application.properties

server.port=8000
#spring mvc 
spring.mvc.view.prefix=/WEB-INF/
spring.mvc.view.suffix=.jsp

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.2.7.RELEASE</version>
  </parent>
  <groupId>cn.springboot</groupId>
  <artifactId>SpringBoot</artifactId>
  <version>1-SNAPSHOT</version>
  <packaging>war</packaging>
  <name>SpringBoot</name>
  <dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <!-- jsp -->
    <dependency>
   <groupId>org.apache.tomcat.embed</groupId>
   <artifactId>tomcat-embed-jasper</artifactId>
   <!-- <scope>provided</scope> -->
</dependency>
<!-- servlet 依赖 -->  
<dependency>  
   <groupId>javax.servlet</groupId>  
   <artifactId>javax.servlet-api</artifactId>  
 <!--   <scope>provided</scope> -->  
</dependency>  
<!-- 添加 JSTL 支持 -->  
<dependency>  
   <groupId>javax.servlet</groupId>  
   <artifactId>jstl</artifactId>  
</dependency>
<!-- tomcat的支持.-->
    <!-- <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-tomcat</artifactId>
       <scope>provided</scope>
    </dependency> -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                   <source>1.7</source>
                   <target>1.7</target>
            </configuration>
       </plugin>
</plugins>

</build>
</project>

测试controller

@Controller
public class TestController {


@RequestMapping(value = "/index")
public String index() {
System.err.println(1111);
return "index";
}


@RequestMapping("/")
@ResponseBody
public String test() {
return "welcome spring boot";
}
}

启动类

@SpringBootApplication
public class SampleController extends SpringBootServletInitializer {


/*
* @Override protected SpringApplicationBuilder
* configure(SpringApplicationBuilder application) { return
* application.sources(SampleController.class); }
*/


public static void main(String[] args) throws Exception {
SpringApplication.run(SampleController.class, args);
}
}


然后就报错了,错误如下:

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Tue Mar 28 16:37:25 CST 2017
There was an unexpected error (type=Internal Server Error, status=500).
Circular view path [index]: would dispatch back to the current handler URL [/index] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)

!!!!!!

视图不对 啊

解决办法:原来上面的application.properties配置文件有问题

去掉MVC改成

server.port=8000
#spring mvc 
spring.view.prefix=/WEB-INF/
spring.view.suffix=.jsp


运行成功


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值