1. 程式人生 > >Spring Boot 錯誤總結(累計30個常見錯誤)

Spring Boot 錯誤總結(累計30個常見錯誤)

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錯誤:

    分析原因:

 @RequestMapping(produces = "text/html")
    public ModelAndView errorHtml(HttpServletRequest request,
            HttpServletResponse response) {
        HttpStatus status = getStatus(request);
        Map<String, Object> model = Collections.unmodifiableMap(getErrorAttributes(
                request, isIncludeStackTrace(request, MediaType.TEXT_HTML)));
        response.setStatus(status.value());
        ModelAndView modelAndView = resolveErrorView(request, response, status, model);
        return (modelAndView == null ? new ModelAndView("error", model) : modelAndView);
    }

    @RequestMapping
    @ResponseBody
    public ResponseEntity<Map<String, Object>> error(HttpServletRequest request) {
        Map<String, Object> body = getErrorAttributes(request,
                isIncludeStackTrace(request, MediaType.ALL));
        HttpStatus status = getStatus(request);
        return new ResponseEntity<Map<String, Object>>(body, status);

          }

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>前新增以下依賴。

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-dependencies</artifactId>
      <version>1.3.3.RELEASE</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

10.當出現錯誤java -jar myApplication.jar

     分析原因:系統報錯,Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

    解決:在Application.java主程式入口中加入以下程式碼:

@Bean
public EmbeddedServletContainerFactory servletContainer() {
       
    TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
    return factory;
       
}

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單元測試報錯

java.lang.NoClassDefFoundError: org/mockito/internal/util/MockUtil

    at org.springframework.boot.test.mock.mockito.MockReset.<clinit>(MockReset.java:56)
    at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.beforeTestMethod(ResetMocksTestExecutionListener.java:44)
    at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:269)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
Caused by: java.lang.ClassNotFoundException: org.mockito.internal.util.MockUtil
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    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的位置新增:

@Override
protected void configure(HttpSecurity http) throws Exception {
       http.headers().frameOptions().disable();
     http
      .csrf().disable();
     http
      .authorizeRequests()
             .anyRequest().authenticated();
      http.formLogin()
          .defaultSuccessUrl("/platform/index",true)
          .loginPage("/login")
          .permitAll()
        .and()
          .logout()
           .logoutUrl("/logout");
      
      http.addFilterBefore(wiselyFilterSecurityInterceptor(),FilterSecurityInterceptor.class);
      
}

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啟動報錯。

Exception in thread "main" java.lang.IllegalStateException: Failed to read Class-Path 
attribute from manifest of jar file:
/E:/myRepository/repositotyExe/repositoty/com/alibaba/fastjson/1.2.32/fastjson-1.2.32.jar
at org.springframework.boot.devtools.restart.ChangeableUrls.
getUrlsFromClassPathOfJarManifestIfPossible(ChangeableUrls.java:110)
at org.springframework.boot.devtools.restart.ChangeableUrls.fromUrlClassLoader
(ChangeableUrls.java:96)
at org.springframework.boot.devtools.restart.DefaultRestartInitializer.getUrls
(DefaultRestartInitializer.java:93)
at org.springframework.boot.devtools.restart.DefaultRestartInitializer.getInitialUrls(
DefaultRestartInitializer.java:56)
at org.springframework.boot.devtools.restart.Restarter.<init>(Restarter.java:140)
at org.springframework.boot.devtools.restart.Restarter.initialize(Restarter.java:546)
at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplication
StartingEvent(RestartApplicationListener.java:67)
at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationEvent
(RestartApplicationListener.java:45)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener
(SimpleApplicationEventMulticaster.java:167)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent
(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent
(SimpleApplicationEventMulticaster.java:122)
at org.springframework.boot.context.event.EventPublishingRunListener.starting(
EventPublishingRunListener.java:68)
at org.springframework.boot.SpringApplicationRunListeners.starting(SpringAppl
icationRunListeners.java:48)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
at com.bldz.springboot.Spring_Boot_JdbcTemplate.App.main(App.java:14)
Caused by: java.util.zip.ZipException: invalid LOC header (bad signature)
	at java.util.zip.ZipFile.read(Native Method)
	at java.util.zip.ZipFile.access$1400(ZipFile.java:60)
	at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:717)
	at java.util.zip.ZipFile$ZipFileInflaterInputStream.fill(ZipFile.java:419)
	at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158)
	at sun.misc.IOUtils.readFully(IOUtils.java:65)
	at java.util.jar.JarFile.getBytes(JarFile.java:425)
	at java.util.jar.JarFile.getManifestFromReference(JarFile.java:193)
	at java.util.jar.JarFile.getManifest(JarFile.java:180)
	at org.springframework.boot.devtools.restart.ChangeableUrls.getUrlsFromCl
assPathOfJarManifestIfPossible(ChangeableUrls.java:107)
	... 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重名導致。

解決:

第一種:出現這種情況一般是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指令碼

#!/bin/bash
export LANG=zh_CN
#tomcat1日誌檔案路徑
export WEB_TOMCAT1=/usr/local/tomcat1/logs
#tomcat2日誌檔案路徑
export WEB_TOMCAT2=/usr/local/tomcat2/logs
#tomcat3日誌檔案路徑
export WEB_TOMCAT3=/usr/local/tomcat3/logs
echo > ${WEB_TOMCAT1}/catalina.out
echo > ${WEB_TOMCAT2}/catalina.out
echo > ${WEB_TOMCAT3}/catalina.out
find ${WEB_TOMCAT1}/* -mtime +5 -type f -exec rm -f {} \;
find ${WEB_TOMCAT2}/* -mtime +5 -type f -exec rm -f {} \;
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.重啟定時任務

[[email protected]]# service crond stop

[[email protected]]# service crond start

28.Springboot清理logs日誌

解決:

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

29.SpringBoot做檔案上傳時出現了The field file exceeds its maximum permitted size of 1048576 bytes.錯誤

解決:

Spring Boot 1.3.x或者之前

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


Spring Boot 1.4.x

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


很多人設定了multipart.maxFileSize但是不起作用,是因為1.4版本以上的配置改了,詳見官方文件:spring boot 1.4
Spring Boot 2.0之後
 

spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=1000MB
@Configuration  
@SpringBootApplication  
public class Application {  
  
    public static void main(String[] args) throws Exception {  
        SpringApplication.run(Application.class, args);  
    }  
  
  
    /**  
     * 檔案上傳配置  
     * @return  
     */  
    @Bean  
    public MultipartConfigElement multipartConfigElement() {  
        MultipartConfigFactory factory = new MultipartConfigFactory();  
        //檔案最大  
        factory.setMaxFileSize("10240MB"); //KB,MB  
        /// 設定總上傳資料總大小  
        factory.setMaxRequestSize("102400MB");  
        return factory.createMultipartConfig();  
    }  
  
}  

錯誤日誌:

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
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
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]
java.lang.IllegalArgumentException: No enum constant org.springframework.web.bind.annotation.RequestMethod.post
    at java.lang.Enum.valueOf(Enum.java:238) ~[na:1.8.0_171]
    at org.springframework.web.bind.annotation.RequestMethod.valueOf(RequestMethod.java:35) ~[spring-web-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at springfox.documentation.swagger.readers.operation.OperationHttpMethodReader.apply(OperationHttpMethodReader.java:50) ~[springfox-swagger-common-2.4.0.jar:2.4.0]
    at springfox.documentation.spring.web.plugins.DocumentationPluginsManager.operation(DocumentationPluginsManager.java:113) [springfox-spring-web-2.4.0.jar:2.4.0]
    at springfox.documentation.spring.web.readers.operation.ApiOperationReader.read(ApiOperationReader.java:80) [springfox-spring-web-2.4.0.jar:2.4.0]
    at springfox.documentation.spring.web.scanners.CachingOperationReader$1.load(CachingOperationReader.java:50) [springfox-spring-web-2.4.0.jar:2.4.0]
    at springfox.documentation.spring.web.scanners.CachingOperationReader$1.load(CachingOperationReader.java:48) [springfox-spring-web-2.4.0.jar:2.4.0]
    at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3628) [guava-20.0.jar:na]
    at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2336) [guava-20.0.jar:na]
    at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2295) [guava-20.0.jar:na]
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2208) [guava-20.0.jar:na]

解決:

將小寫post改成大寫就好了  或者 @RequestMapping 註解增加 method = RequestMethod.POST

	@ApiOperation(value="獲取所有的區域資訊", notes="獲取區域列表", httpMethod = "GET", response =Area.class, produces = "application/json")
	@RequestMapping(value = "/listarea", method = RequestMethod.GET)
或者
	@ApiOperation(value="獲取所有的區域資訊", notes="獲取區域列表", httpMethod = "POST", response =Area.class, produces = "application/json")
	@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)):

<repositories>
    <repository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>https://repo.spring.io/snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>https://repo.spring.io/snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </pluginRepository>
    <pluginRepository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

+ 若在自己配置了國內maven庫映象後無法下載以上版本,則請將映象註釋掉,用maven預設的中央倉庫下載(如果覺得太慢,就用科學上網)

 32. 遇到Eureka Client無法啟動的情況

解決:
+ 如果用的版本是SpringBoot 2.0.0.M3和SpringCloud Finchley.M2按照視訊可正常啟動
+ 如果是高版本無法啟動時,需要在pom.xml中加入如下依賴:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

33.order專案的server模組不能正常引入product專案中的client模組
出現原因
+ 可能是因為product專案的client模組還沒有打包成功,order專案的server模組不能找不到該依賴
解決:
+ 1.先對product專案,在父模組下進行maven打包

mvn clean install -Dmaven.test.skip=true

+ 2.再進入order專案,用同樣的命令再進行打包

待續....

相關推薦

轉:Spring Boot 錯誤總結累計30常見錯誤

版權宣告:本文為博主原創文章,未經博主允許不得轉載。    https://blog.csdn.net/qq_32447301/article/details/77161272 1.新建Spring boot,出現src的包上出現錯誤的叉號:   

Spring Boot 錯誤總結累計30常見錯誤

1.新建Spring boot,出現src的包上出現錯誤的叉號:    分析原因: 你要更新一下選擇專案-----Maven----Updata project,或者刪除jar包---Libraries---Maven Dependencies,然後重新關閉eclipse,

三年的python開發經驗,總結出這【30常見錯誤】,避免重蹈覆轍!!!

導讀:在這篇文章中,我將總結新老Python程式設計師常犯的一些錯誤,以幫助你們在自己的工作避免犯同樣或類似錯誤。 在這篇文章中,我將總結新老Python程式設計師常犯的一些錯誤,以幫助你們在自己的工作避免犯同樣或類似錯誤。 首先我要說明一下的是,這些都是來源於第一手的經驗。我以講授Python的知識為生

Spring boot使用總結校驗[email protected] 使用

spring boot 1.4預設使用 hibernate validator 5.2.4 Final實現校驗功能。hibernate validator 5.2.4 Final是JSR 349 Bean Validation 1.1的具體實現。 一 初步使用

Spring Boot 學習總結 ---入口類和@SpringBootApplication

入口類和@SpringBootApplication SpringBoot通常有一個名為*Application的入口類,入口類裡有一個main方法,這個main方法是一個標準的java應用的入口方法。在main方法中使用SpringApplication.run(*App

Spring Boot學習總結14——Spring Boot常見面試題彙總

1、什麼是 Spring Boot? Spring Boot 是 Spring 開源組織下的子專案,是 Spring 元件一站式解決方案,主要是簡化了使用 Spring 的難度,簡省了繁重的配置,提供了各種啟動器,開發者能快速上手。 2、為什麼要用 Spring Boot

Spring Boot學習總結10——SpringBoot打包成Docker映象

<build><!--定義jar檔名,可以自定義--><finalName>${project.name}-${project.version}</finalN

Spring Boot學習總結1——Spring Boot入門

摘要:Spring Boots是為了幫助開發人員很容易的創建出獨立執行和產品級別的基於 Spring 框架的應用。 從 Spring Boot 專案名稱中的 Boot 可以看出來,Spring

Spring Boot學習總結7——SpringBoot之於Spring優勢

一、Spring在Java EE開發中是實際意義上的標準,但我們在開發Spring的時候可能會遇到以下令人頭疼的問題:(1)大量配置檔案的定義;(2)與第三方軟體整合的技術問題,Spring每個新版本的

Spring Boot學習總結8——SpringBoot Common application propertiesapplication.properties詳解

# =================================================================== # COMMON SPRING BOOT PROPERTIES # # This sample file is provided as a guideline. Do N

Spring Boot學習總結2——Spring Boot整合Jsp

怎麼使用jsp上面起了疑問,查閱了多方資料,找到過其他人的部落格的描述,也找到了spring在github上的給出的例子,看完後稍微改動後成功 整合jsp,於是決定將整合過程記載下來。 無論使用

Spring Boot學習總結4——使用Springloaded進行熱部署

我在開發的時候,總是會及時對自己的程式進行測試,總是頻繁的重啟web server,容器不煩我們都覺得煩了。 dependencys目錄下增加: <dependency><group

Spring-boot 之 Swagger2打造不一樣的api

plugin itl pid 研究 ssa any cati plugins ast 一、Swagger2是什麽? Swagger 是一款RESTFUL接口的文檔在線自動生成+功能測試功能軟件。 Swagger 是一個規範和完整的框架,用於生成、描述、調用和可視化 RE

Ruby 開發環境安裝linux、mac,遇到的錯誤總結使後人避免入坑

一、linux安裝ruby時遇到的錯誤 首先講一下為什麼不寫Windows的,個人建議,最好不要用Windows環境,問題很多,需要安裝的東西更多,而且未知的錯誤多,網上不一定查的到,我也安裝過Windows的,也成功過,但是,有時執行會報錯,後來放棄了,安了個Linux的,再後來用了mac系統,

Python程式設計師的30常見錯誤

在這篇文章中,我將總結新老Python程式設計師常犯的一些錯誤,以幫助你們在自己的工作避免犯同樣或類似錯誤。 首先我要說明一下的是,這些都是來源於第一手的經驗。我以講授Python的知識為生。在過去的7年裡,我已經給上千名學生講授上百堂Python的課程,同時看著這些學生們犯同樣的錯。也就是

spring boot入門指南來自官網入門指南

1. spring boot 可以使你通過很小的前期配置儘可能快的啟動和執行專案,spring boot用自己的觀點來建立產品已有的應用 2. 啟動:     使用spring boot建立一個應用:        &n

Spring boot 瞭解(四)整合mybatis和事務管理

對於SpringBoot 整合mybatis和事務管理的記錄 (學習地址:https://www.majiaxueyuan.com/front/couinfo/36) 目錄 1.整合mybatis 2.事務管理 1.整合mybatis 1.新增依賴 <de

Spring boot 瞭解(三)整合thymeleaf和thymeleaf顯示

學習到整合thymeleaf及其顯示資料的部分,記錄如下: (學習網址:https://www.majiaxueyuan.com/front/couinfo/36) SpringBoot 不推薦使用jsp 因為jsp會編譯成Servlet 屬於重量級 Springboot中推薦使用Thy

Spring Boot整合Redis附帶序列化方式對比

一、快取資料庫效能Redis、memcached、EhcacheRedis儲存資料型別豐富,對於儲存資料量不是很大的情況下處理效能效果較好、支援持久化memcached對於大量的資料儲存和讀取效能要優於Redis、沒有持久化Ehcache最大的特點是輕量級,而且儲存的資料型別

Spring-Batch學習總結1——重要概念,環境搭建,名詞解釋,第一項目及異常處理

img truct 設定 uil sna sta col key services Spring-batch框架學習總結(1)一.初識Spring-batch框架:1.核心名詞解釋:Job:是Spring-batch框架的核心概念,它包含了批處理的所有操作Step:每一個J