spring Boot报错 之五种(不打包运行)

来源:互联网 发布:创作漫画的软件 编辑:程序博客网 时间:2024/05/14 18:09


Whitelabel Error Page

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

Fri Aug 18 13:01:46 CST 2017
There was an unexpected error (type=Not Found, status=404).
No message available


其一: 

之前百度,google,必应,都TM 不好使  都是是其他人自己手欠的原因,低级原因(打错字),但没想到的是自己也犯低级错误

@SpringBootApplication 这个注解的类要放在最外围的包里,一遍能管理到其他 controller ,  如图

红框里的就是 spring Boot 的配置应用,要放在绿框的外面包里




其二:

有配置properties资源文件 键值对 像这样的

spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp

应该改为

spring.mvc.view.prefix=/WEB-INF/jsp/

spring.mvc.view.suffix=.jsp

(注意默认的配置key 不要写错了)

  spring boot appliaction配置文件默认配置项

其三:

properties配置资源文件 引用文件(toolbox.xml) 但是项目里没有这个文件 找不到文件
spring.velocity.toolbox-config-location = toolbox.xml

其四:访问url 的问题

说说自己干了什么傻逼事

这是我配置的应用类

package com.spring.boot;import java.util.Date;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;import org.springframework.web.bind.annotation.RestController;@SpringBootApplication//等于@Configuration,@EnableAutoConfiguration,@ComponentScan@RestController//等于@Controller和@ResponseBody注解。//@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})//Spring Boot会创建默认的内存数据库的数据源DataSource,如果你自己创建了DataSource,Spring Boot就不会创建默认的DataSourcepublic class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);//或者/*SpringApplication application = new SpringApplication(DemoApplication.class);application.run(args);*///或者/*new SpringApplicationBuilder()        .showBanner(false)        .sources(Application.class)        .run(args);*/}@RequestMapping("/")String home() {System.out.println(2324234);    return "index";}@RequestMapping("/now")String hehe() {    return "现在时间:" + (new Date()).toLocaleString();}}




项目名叫 jxTest  ,写惯了web 项目访问的小伙伴都懂 http://localhost:8080/jxTest/now 这样写 理所当然,但是

spring boot 就是跟人家不一样, 正确的写法应该是  http://localhost:8080/now 


(update  )

其五: 

正常情况下,配置视图的前后缀是没有问题的, 大多数情况为了安全, 把页面想放到WEB-INF 下 如果pom文件没有添加这一句

<!-- 配置 页面的记得引用 这个包 , 直接返回json 不需要 -->       <dependency>           <groupId>org.apache.tomcat.embed</groupId>           <artifactId>tomcat-embed-jasper</artifactId>           <scope>provided</scope>       </dependency>

也是会报上面的错



以上总结自己所查询的几个出现这个错误的原因


原创粉丝点击