查了一天了也没查到问题,我配置了mvc的前缀和后缀,可就是返回不了jsp,是打的war包有问题吗,
还是缺少什么web的包,它只会报Circular view path [/main]: would dispatch back to the current handler URL [/main] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.),实在是查不到怎么解决了,照着springboot的官方web例子改也不行,直接返回了字符串而不是jsp页面,真心求各位帮帮忙。
yml配置文件里的源码
mvc:
view:
prefix: /WEB-INF/jsp/
suffix: .jsp
gradle的依赖包引入
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'org.springframework.boot:spring-boot-starter-freemarker'
compile 'org.springframework.boot:spring-boot-starter-groovy-templates'
compile 'org.springframework.boot:spring-boot-starter-jdbc'
compile 'com.h2database:h2:1.4.190'
compile 'com.alibaba:fastjson:1.2.7'
compile 'com.google.guava:guava:18.0'
compile 'org.springframework.boot:spring-boot-starter-redis'
compile 'org.springframework.boot:spring-boot-starter-web'
// compile 'org.springframework.boot:spring-boot-starter-jetty'
compile 'org.springframework.boot:spring-boot-starter-tomcat'
compile 'org.apache.tomcat.embed:tomcat-embed-jasper'
compile 'javax.servlet:jstl'
compile 'org.apache.directory.studio:org.apache.commons.lang:2.6'
compile 'commons-io:commons-io:2.4'
compile 'mysql:mysql-connector-java'
testCompile 'org.springframework.boot:spring-boot-starter-test'
compile 'org.springframework.boot:spring-boot-starter-data-rest'
compile 'org.springframework.boot:spring-boot-configuration-processor'
compile 'com.googlecode.xmemcached:xmemcached:2.0.0'
controller
@RequestMapping("/main")
public ModelAndView welcome1() {
logger.error("111111111111111")
return new ModelAndView("/main")
}
日志能打出来,但是这个main.jsp找不到
war包的目录结构
又去查了一下,视频和例子都在说引入
compile 'org.springframework.boot:spring-boot-starter-tomcat'
compile 'org.apache.tomcat.embed:tomcat-embed-jasper'
两个依赖后,注释为@Controller,直接return字符串类型的jsp名就可以
可就是还是不行,ViewResolver好像没有设置
配置文件没配对吧
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
<!-- scan the package and the sub package -->
<context:component-scan base-package="test.SpringMVC"/>
<!-- don't handle the static resource -->
<mvc:default-servlet-handler />
<!-- if you use annotation you must configure following setting -->
<mvc:annotation-driven />
<!-- configure the InternalResourceViewResolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
id="internalResourceViewResolver">
<!-- 前缀 -->
<property name="prefix" value="/WEB-INF/jsp/" />
<!-- 后缀 -->
<property name="suffix" value=".jsp" />
</bean>
http://www.admin10000.com/document/6436.html
spring-boot:run
springboot不支持jsp 如果想jsp的话 不能打成jar包 只能打成war包 并且在tomcat中运行
spring boot 使用jsp的时候需要用jar包跑必须要在编译的时候将jsp编译到jar里面.
.
<!-- 打包时将jsp文件拷贝到META-INF目录下-->
<!-- 指定resources插件处理哪个目录下的资源文件 -->
src/main/webapp
<!--注意此次必须要放在此目录下才能被访问到-->
META-INF/resources
/
因为springboot项目默认是不支持jsp的,
第一步:需要我们自己配置jar包依赖:
<dependency><!-- SpringBoot 外部tomcat支持 -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency><!--jsp页面使用jstl标签-->
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency><!--用于编译jsp-->
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
第二步:在application.yml中添加
#jsp文件配置
mvc:
view:
prefix: /WEB-INF/jsp/
suffix: .jsp
第三步:在项目结构src/main下创建和java、resources平级的webapp及其子文件WEB-INF
问题:
1.Controller层找不到jsp文件?
将自己创建的webaap指定为项目的web资源文件夹!
步骤:File - Project Structure - Modules - 中间栏Web - 右边栏Web Resource Directorie下的 资源路径改为E:\IT\idea-workspace\bookstore\src\main\webapp 最后点击Apply
2.页面报错404?
检查application.yml配置文件中的jsp文件路径,及其可能是yml文件中配置的jsp路径与jsp页面在项目中的路径不一致