当前位置:   article > 正文

Spring Boot 错误总结(累计30个常见错误)_spring boot报错

spring boot报错

1.新建Spring boot,出现src的包上出现错误的叉号:

   分析原因: 你要更新一下选择项目-----Maven----Updata project,或者删除jar包---Libraries---Maven Dependencies,然后重新关闭eclipse,重新启动!

2.如果你项目与别人一样,怎么试都不行,还是报错,或者其它问题:

    分析原因:记住一句话,小问题重启,大问题重装!

3.启动时出现警告:

   分析原因: 项目目录设计错误

                     src
                     |_main
                     |_java
                     |_package name
                     |_xxxController

                     |_Application

                    application.Java 文件不能直接放在main/java文件夹下,必须要建一个包把他放进去

4.Web项目无法访问resources/templates/xxx.html文件

     分析原因:没有导入相关模板的依赖

3.启动时出现NoSuchBeanDefinitionException: No qualifying bean of type [con: No qualifying bean of type

    分析原因:@SpringApplicationConfiguration

5.BasicErrorController提供两种返回错误一种是页面返回、当你是页面请求的时候就会返回页面,另外一种是json请求的时候就会返回json错误:

    分析原因: 

  1. @RequestMapping(produces = "text/html")
  2. public ModelAndView errorHtml(HttpServletRequest request,
  3. HttpServletResponse response) {
  4. HttpStatus status = getStatus(request);
  5. Map<String, Object> model = Collections.unmodifiableMap(getErrorAttributes(
  6. request, isIncludeStackTrace(request, MediaType.TEXT_HTML)));
  7. response.setStatus(status.value());
  8. ModelAndView modelAndView = resolveErrorView(request, response, status, model);
  9. return (modelAndView == null ? new ModelAndView("error", model) : modelAndView);
  10. }
  11. @RequestMapping
  12. @ResponseBody
  13. public ResponseEntity<Map<String, Object>> error(HttpServletRequest request) {
  14. Map<String, Object> body = getErrorAttributes(request,
  15. isIncludeStackTrace(request, MediaType.ALL));
  16. HttpStatus status = getStatus(request);
  17. return new ResponseEntity<Map<String, Object>>(body, status);
  18. }

6.javax.servlet.ServletException: Circular view path [login]: would dispatch back to the current handler URL [/login] again出现错误

 分析原因:

当没有声明ViewResolver时,spring会注册一个默认的ViewResolver,就是JstlView的实例, 该对象继承自InternalResoureView。
JstlView用来封装JSP或者同一Web应用中的其他资源,它将model对象作为request请求的属性值暴露出来, 并将该请求通过javax.servlet.RequestDispatcher转发到指定的URL.
Spring认为, 这个view的URL是可以用来指定同一web应用中特定资源的,是可以被RequestDispatcher转发的。
也就是说,在页面渲染(render)之前,Spring会试图使用RequestDispatcher来继续转发该请求。

解决:消除缺省转发,修改view和path,让他们不同名。

7.当以.yml结尾的配置出现报错:

    分析原因:

                 if xxxxxx:

                (空格)xxxxx

8.当出现错误java.net.BindException: Address already in use: bind

 解决:打开Windows进程管理器结束javaw.exe,重新运行。并在每次启动程序前,结束之前的运行。

9.当出现错误Spring Boot Error: java.lang.NoSuchMethodError

   解决:仔细搜索报错信息中的方法名,查看出错类中是否缺少某方法。笔者此次报错由于org.springframework.core.ResolvableType.forInstance方法找不到所致,又想起 之前在pom.xml中移除了parent依赖,想起是否改文件没有完整下载。查询了官网说明:当移除parent依赖时,需要增加spring-boot-dependencies的依赖。因此pom.xml中在<dependencies>前新增以下依赖。

  1. <dependencyManagement>
  2. <dependencies>
  3. <dependency>
  4. <groupId>org.springframework.boot</groupId>
  5. <artifactId>spring-boot-dependencies</artifactId>
  6. <version>1.3.3.RELEASE</version>
  7. <type>pom</type>
  8. <scope>import</scope>
  9. </dependency>
  10. </dependencies>
  11. </dependencyManagement>

10.当出现错误java -jar myApplication.jar

     分析原因:系统报错,Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

    解决:在Application.java主程序入口中加入以下代码:

  1. @Bean
  2. public EmbeddedServletContainerFactory servletContainer() {
  3. TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
  4. return factory;
  5. }

11.启动spring boot报错

    解决:这个原因是maven依赖包冲突,有重复的依赖。 检查一下你引入的jar包里面是不是有相同的方法名。

12.结果启动时报错BeanCreationException:

org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'userController':
Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.caizhaotu.dao.user.UserRepository com.caizhaotu.controller.user.UserController.userRepository;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Invocation of init method failed; nested exception is java.util.NoSuchElementException

解决:application.java 可以放在controller、service、dao层都可以,但是要保证application.java 包位置处于所有层的上级,比如com.xxx.web、com.xxx.service、com.xxx.dao。把application.java放在com.xxx即可。@SpringBootApplication 注解效果等于 @Configuration,@EnableAutoConfiguration 及 @ComponentScan 这三个注解一起使用,所以不要在 Controller 在启动类上面添加 @EnableAutoConfiguration 。

13.class TaskImpl 中注入失败,目标变量为null并报错

     解决:1.一些业务细节代码已经单机跑通了。 2.使用了@SpringBootApplication进行自动化配置与扫描。3.没有遗漏的@Component。

14.Spring Boot单元测试报错

  1. java.lang.NoClassDefFoundError: org/mockito/internal/util/MockUtil
  2. at org.springframework.boot.test.mock.mockito.MockReset.<clinit>(MockReset.java:56)
  3. at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.beforeTestMethod(ResetMocksTestExecutionListener.java:44)
  4. at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:269)
  5. at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
  6. at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
  7. at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
  8. at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
  9. at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
  10. at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
  11. at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
  12. at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
  13. at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
  14. at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
  15. at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
  16. at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
  17. at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
  18. at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
  19. at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
  20. at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
  21. at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
  22. at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
  23. at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
  24. at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
  25. Caused by: java.lang.ClassNotFoundException: org.mockito.internal.util.MockUtil
  26. at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
  27. at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  28. at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
  29. at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

  解决:在build.gradle引用compile中加入[group: 'org.mockito', name: 'mockito-all', version: '1.10.19']

15.eclipse新建springboot的项目,出现以下错误The type org.springframework.context.ConfigurableApplicationContext cannot be resolved. It is indirectly referenced from required .class files

  解决:执行 mvn dependency:purge-local-repository   mvn clean

16.[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.3.RELEASE:repackage (default-cli) on project springboot_1: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:1.4.3.RELEASE:repackage failed: Source must refer to an existing file -> [Help 1]

[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException Process finished with exit code 1

   解决:直接使用maven的package命令,即可完成打包,若有新的内容添加,可以使用spring-boot-maven-plugin的repackage命令.详细步骤如下图

17.使用spring boot 使用druid,启动tomcat时报错:提示由于unregister mbean error导致无法启动启动类。

     解决:在配置文件加入spring.jmx.enabled: false

18. 出现这样的错误:at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]

      解决:删除jar包,重新导入。

19.在spring boot项目中出现不能加载iframe 页面报一个"Refused to display 'http://......' in a frame because it set 'X-Frame-Options' to 'DENY'. "错误

      解决:因spring Boot采取的java config,在配置spring security的位置添加:

  1. @Override
  2. protected void configure(HttpSecurity http) throws Exception {
  3. http.headers().frameOptions().disable();
  4. http
  5. .csrf().disable();
  6. http
  7. .authorizeRequests()
  8. .anyRequest().authenticated();
  9. http.formLogin()
  10. .defaultSuccessUrl("/platform/index",true)
  11. .loginPage("/login")
  12. .permitAll()
  13. .and()
  14. .logout()
  15. .logoutUrl("/logout");
  16. http.addFilterBefore(wiselyFilterSecurityInterceptor(),FilterSecurityInterceptor.class);
  17. }

20.错误提示如下:

Caused by: java.lang.IllegalStateException: Tomcat connector in failed state

at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:159) ~[spring-boot-1.3.6.RELEASE.jar:1.3.6.RELEASE]

... 15 common frames omitted

2017-04-14 19:36:55.419 ERROR 19420 --- [  restartedMain] o.a.coyote.http11.Http11NioProtocol      : Failed to start end point associated with ProtocolHandler ["http-nio-8080"]

    解决:是NI server占据了8080端口。

21.出现springboot框架maven构建fastJson启动报错。

  1. Exception in thread "main" java.lang.IllegalStateException: Failed to read Class-Path
  2. attribute from manifest of jar file:
  3. /E:/myRepository/repositotyExe/repositoty/com/alibaba/fastjson/1.2.32/fastjson-1.2.32.jar
  4. at org.springframework.boot.devtools.restart.ChangeableUrls.
  5. getUrlsFromClassPathOfJarManifestIfPossible(ChangeableUrls.java:110)
  6. at org.springframework.boot.devtools.restart.ChangeableUrls.fromUrlClassLoader
  7. (ChangeableUrls.java:96)
  8. at org.springframework.boot.devtools.restart.DefaultRestartInitializer.getUrls
  9. (DefaultRestartInitializer.java:93)
  10. at org.springframework.boot.devtools.restart.DefaultRestartInitializer.getInitialUrls(
  11. DefaultRestartInitializer.java:56)
  12. at org.springframework.boot.devtools.restart.Restarter.<init>(Restarter.java:140)
  13. at org.springframework.boot.devtools.restart.Restarter.initialize(Restarter.java:546)
  14. at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplication
  15. StartingEvent(RestartApplicationListener.java:67)
  16. at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationEvent
  17. (RestartApplicationListener.java:45)
  18. at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener
  19. (SimpleApplicationEventMulticaster.java:167)
  20. at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent
  21. (SimpleApplicationEventMulticaster.java:139)
  22. at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent
  23. (SimpleApplicationEventMulticaster.java:122)
  24. at org.springframework.boot.context.event.EventPublishingRunListener.starting(
  25. EventPublishingRunListener.java:68)
  26. at org.springframework.boot.SpringApplicationRunListeners.starting(SpringAppl
  27. icationRunListeners.java:48)
  28. at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
  29. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
  30. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
  31. at com.bldz.springboot.Spring_Boot_JdbcTemplate.App.main(App.java:14)
  32. Caused by: java.util.zip.ZipException: invalid LOC header (bad signature)
  33. at java.util.zip.ZipFile.read(Native Method)
  34. at java.util.zip.ZipFile.access$1400(ZipFile.java:60)
  35. at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:717)
  36. at java.util.zip.ZipFile$ZipFileInflaterInputStream.fill(ZipFile.java:419)
  37. at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158)
  38. at sun.misc.IOUtils.readFully(IOUtils.java:65)
  39. at java.util.jar.JarFile.getBytes(JarFile.java:425)
  40. at java.util.jar.JarFile.getManifestFromReference(JarFile.java:193)
  41. at java.util.jar.JarFile.getManifest(JarFile.java:180)
  42. at org.springframework.boot.devtools.restart.ChangeableUrls.getUrlsFromCl
  43. assPathOfJarManifestIfPossible(ChangeableUrls.java:107)
  44. ... 16 more

    解决:删除maven仓库下的 /E:/myRepository/repositotyExe/repositoty/com/alibaba/fastjson/1.2.32/fastjson-1.2.32.jar,重新编译即可!

22.Spring Boot Maven项目启动报错
ERROR 2172 --- [ main] o.s.boot.SpringApplication : Application startup failed    org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Jetty servlet container

at org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainer.start(JettyEmbeddedServletContainer.java:124) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:293) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:141) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:764) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:357) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:305) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1124) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1113) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
at com.easemob.weichat.gateway.im.IMRoutewayServerStarter.main(IMRoutewayServerStarter.java:28) [classes/:na]
Caused by: java.net.BindException: Address already in use
at sun.nio.ch.Net.bind0(Native Method) ~[na:1.8.0_112]
at sun.nio.ch.Net.bind(Net.java:433) ~[na:1.8.0_112]
at sun.nio.ch.Net.bind(Net.java:425) ~[na:1.8.0_112]
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) ~[na:1.8.0_112]
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74) ~[na:1.8.0_112]
at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:321) ~[jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80) ~[jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:236) ~[jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) ~[jetty-util-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainer.start(JettyEmbeddedServletContainer.java:118) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
... 10 common frames omitted

     解决:典型的端口被占用,,改下你的boot启动端口。

23.The type javax.servlet.http.HttpServletRequest cannot be resolved. It is indirectly referenced from
required .class files

是缺少serverlet的引用库,

  解决:
    1.工程右键-properties->java build path
    2.在java build path的libraries tab页中选择Add external Jars按钮
   3. 选择eclipse的安装目录,我本机的路径如下,你自己需要根据自己的路径查找添加。E:\eclipse-java-indigo-SR1-win32\eclipse\plugins 选择javax.servlet.jsp_2.0.0.v201101211617.jar;javax.servlet_2.5.0.v201103041518.jar 进行添加即可
   注释:由于版本不同,文件包名可能稍有区别。

24.Ambiguous mapping. Cannot map 'XXXController' method

解决:

@RequestMapping(value=XXX) 可能是同一个Controller或者 是不同的Controller。 XXX重名导致。

25.打开Eclipse提示“The default workspace “xxxx” is in use or cannot be created Please choose a different one“

解决:

第一种:出现这种情况一般是workspace的配置文件中出现了.lock文件(workspace/.metadata/.lock),锁定了workspace。把.lock文件删除即可。如果该文件不能删除,可能是因为javaw.exe进程未结束,结束该进程及eclipse.exe进程即可删除。
第二种:重新启动电脑。

26.missing artifact com.oracle:ojdbc6:jar:11.2.0.1.0问题解决 ojdbc包pom.xml出错

原因:Oracle的ojdbc.jar是收费的,所以maven的中央仓库中没有这个资源,只能通过配置本地库才能加载到项目中去。

解决:

1.首先确定你是否有安装oracle,如果有安装的话,找到ojdbc6.jar包
D:\app\Administrator\product\11.2.0\dbhome_1\jdbc\lib\ojdbc6.jar(这是我路径,你们的可能与我不同)
2.将ojdbc6.jar包添加到maven本地仓库或者手动加入jar包。
3.最后找到项目的pom.xml引入如下代码,右击项目名称,找到maven,找到update project更新下就ok了。

27.tomcat用shell定时清理日志

解决:

1.写一个/usr/local/script/cleanTomcatlog.sh脚本

  1. #!/bin/bash
  2. export LANG=zh_CN
  3. #tomcat1日志文件路径
  4. export WEB_TOMCAT1=/usr/local/tomcat1/logs
  5. #tomcat2日志文件路径
  6. export WEB_TOMCAT2=/usr/local/tomcat2/logs
  7. #tomcat3日志文件路径
  8. export WEB_TOMCAT3=/usr/local/tomcat3/logs
  9. echo > ${WEB_TOMCAT1}/catalina.out
  10. echo > ${WEB_TOMCAT2}/catalina.out
  11. echo > ${WEB_TOMCAT3}/catalina.out
  12. find ${WEB_TOMCAT1}/* -mtime +5 -type f -exec rm -f {} \;
  13. find ${WEB_TOMCAT2}/* -mtime +5 -type f -exec rm -f {} \;
  14. find ${WEB_TOMCAT3}/* -mtime +5 -type f -exec rm -f {} \;

2 .设置cleanTomcatlog.sh脚本可执行

chmod a+x cleanTomcatlog.sh

3.在控制台上输入以下命令

  crontab -e

4.按i键编辑这个文本文件,输入以下内容,每天凌晨4:30重启tomcat

  30 04 * * * /usr/local/script/cleanTomcatlog.sh

按esc键退出编辑,输入wq回车保存

5.重启定时任务

  1. [root@]# service crond stop
  2. [root@]# service crond start

28.Springboot清理logs日志

解决:

  1. #!/bin/bash
  2. #路径
  3. logs_path="/mnt/springboot/logs"
  4. find $logs_path -mtime +30 -name "access.log.log.*" -exec rm -rf {} \;
  5. find $logs_path -mtime +30 -name "*.log.*" -exec rm -rf {} \;
  6. >$logs_path/error.log;

29.SpringBoot做文件上传时出现了The field file exceeds its maximum permitted size of 1048576 bytes.错误

解决:

Spring Boot 1.3.x或者之前

  1. multipart.maxFileSize=100MB
  2. multipart.maxRequestSize=1000MB


Spring Boot 1.4.x

  1. spring.http.multipart.maxFileSize=100MB
  2. spring.http.multipart.maxRequestSize=1000MB


很多人设置了multipart.maxFileSize但是不起作用,是因为1.4版本以上的配置改了,详见官方文档:spring boot 1.4
Spring Boot 2.0之后
 

  1. spring.servlet.multipart.max-file-size=100MB
  2. spring.servlet.multipart.max-request-size=1000MB
  1. @Configuration
  2. @SpringBootApplication
  3. public class Application {
  4. public static void main(String[] args) throws Exception {
  5. SpringApplication.run(Application.class, args);
  6. }
  7. /**
  8. * 文件上传配置
  9. * @return
  10. */
  11. @Bean
  12. public MultipartConfigElement multipartConfigElement() {
  13. MultipartConfigFactory factory = new MultipartConfigFactory();
  14. //文件最大
  15. factory.setMaxFileSize("10240MB"); //KB,MB
  16. /// 设置总上传数据总大小
  17. factory.setMaxRequestSize("102400MB");
  18. return factory.createMultipartConfig();
  19. }
  20. }

30.spring使用swagger这个错误怎么解决,项目能运行,就是一直报错误。

错误日志:

  1. 09:09:55.044 logback [RMI TCP Connection(9)-127.0.0.1] DEBUG s.d.s.w.r.o.OperationResponseClassReader - Setting spring response class to:ServerResponse
  2. 09:09:55.044 logback [RMI TCP Connection(9)-127.0.0.1] DEBUG s.d.s.r.o.OperationAuthReader - Authorization count 0 for method resetPassword
  3. 09:09:55.046 logback [RMI TCP Connection(9)-127.0.0.1] ERROR s.d.s.r.o.OperationHttpMethodReader - Invalid http method: postValid ones are [[Lorg.springframework.web.bind.annotation.RequestMethod;@5c8bcf2a]
  4. java.lang.IllegalArgumentException: No enum constant org.springframework.web.bind.annotation.RequestMethod.post
  5. at java.lang.Enum.valueOf(Enum.java:238) ~[na:1.8.0_171]
  6. at org.springframework.web.bind.annotation.RequestMethod.valueOf(RequestMethod.java:35) ~[spring-web-4.3.12.RELEASE.jar:4.3.12.RELEASE]
  7. at springfox.documentation.swagger.readers.operation.OperationHttpMethodReader.apply(OperationHttpMethodReader.java:50) ~[springfox-swagger-common-2.4.0.jar:2.4.0]
  8. at springfox.documentation.spring.web.plugins.DocumentationPluginsManager.operation(DocumentationPluginsManager.java:113) [springfox-spring-web-2.4.0.jar:2.4.0]
  9. at springfox.documentation.spring.web.readers.operation.ApiOperationReader.read(ApiOperationReader.java:80) [springfox-spring-web-2.4.0.jar:2.4.0]
  10. at springfox.documentation.spring.web.scanners.CachingOperationReader$1.load(CachingOperationReader.java:50) [springfox-spring-web-2.4.0.jar:2.4.0]
  11. at springfox.documentation.spring.web.scanners.CachingOperationReader$1.load(CachingOperationReader.java:48) [springfox-spring-web-2.4.0.jar:2.4.0]
  12. at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3628) [guava-20.0.jar:na]
  13. at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2336) [guava-20.0.jar:na]
  14. at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2295) [guava-20.0.jar:na]
  15. at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2208) [guava-20.0.jar:na]

解决:

将小写post改成大写就好了  或者 @RequestMapping 注解增加 method = RequestMethod.POST

  1. @ApiOperation(value="获取所有的区域信息", notes="获取区域列表", httpMethod = "GET", response =Area.class, produces = "application/json")
  2. @RequestMapping(value = "/listarea", method = RequestMethod.GET)
  3. 或者
  4. @ApiOperation(value="获取所有的区域信息", notes="获取区域列表", httpMethod = "POST", response =Area.class, produces = "application/json")
  5. @RequestMapping(value = "/listarea", method = RequestMethod.POST)

31. 无法下载SpringBoot 2.0.0.M3和SpringCloud Finchley.M2

解决:
+ 在pom.xml文件里加上如下代码(可参考[product的pom.xml](https://gitlab-demo.com/SpringCloud_Sell/product/blob/master/pom.xml)):

  1. <repositories>
  2. <repository>
  3. <id>spring-snapshots</id>
  4. <name>Spring Snapshots</name>
  5. <url>https://repo.spring.io/snapshot</url>
  6. <snapshots>
  7. <enabled>true</enabled>
  8. </snapshots>
  9. </repository>
  10. <repository>
  11. <id>spring-milestones</id>
  12. <name>Spring Milestones</name>
  13. <url>https://repo.spring.io/milestone</url>
  14. <snapshots>
  15. <enabled>false</enabled>
  16. </snapshots>
  17. </repository>
  18. </repositories>
  19. <pluginRepositories>
  20. <pluginRepository>
  21. <id>spring-snapshots</id>
  22. <name>Spring Snapshots</name>
  23. <url>https://repo.spring.io/snapshot</url>
  24. <snapshots>
  25. <enabled>true</enabled>
  26. </snapshots>
  27. </pluginRepository>
  28. <pluginRepository>
  29. <id>spring-milestones</id>
  30. <name>Spring Milestones</name>
  31. <url>https://repo.spring.io/milestone</url>
  32. <snapshots>
  33. <enabled>false</enabled>
  34. </snapshots>
  35. </pluginRepository>
  36. </pluginRepositories>

+ 若在自己配置了国内maven库镜像后无法下载以上版本,则请将镜像注释掉,用maven默认的中央仓库下载(如果觉得太慢,就用科学上网)

 32. 遇到Eureka Client无法启动的情况

解决:
+ 如果用的版本是SpringBoot 2.0.0.M3和SpringCloud Finchley.M2按照视频可正常启动
+ 如果是高版本无法启动时,需要在pom.xml中加入如下依赖:

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-web</artifactId>
  4. </dependency>

33.order项目的server模块不能正常引入product项目中的client模块
出现原因
+ 可能是因为product项目的client模块还没有打包成功,order项目的server模块不能找不到该依赖
解决:
+ 1.先对product项目,在父模块下进行maven打包

mvn clean install -Dmaven.test.skip=true

+ 2.再进入order项目,用同样的命令再进行打包

待续....

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/624866
推荐阅读
相关标签
  

闽ICP备14008679号