項目踩坑記錄0

線項目bug記錄

1:依賴報錯

使用idea中遇到的依賴報錯問題,當依賴的版本報紅時,可以右鍵代碼空白處,然後然後選擇maven——》reimport 刷新即可

2:依賴報錯

在導入maven依賴時,直接複製粘貼全部依賴時會報錯。只有一個一個手動導入才正常。(注意不能複製粘貼,只能手動導入)

3:依賴報錯

在idea中使用maven工程導入pom依賴時,pom文件中的依賴有報錯,但是在maven本地倉庫中是有所依賴的jar包的,此時應該進入maven的設置中,更新maven倉庫的依賴
具體步驟如下 setting -> 搜索maven -> Repositores -> update
在拼接字符串是要儘量使用Stringbuffer或者Stringbuilder儘可能不適用+號拼接,這樣當需要拼接的字符串比較多時,可以很明顯的提高程序的效率。

4:導包

在導入包時一定要導入正確的包,以後在寫記錄複製代碼時,必須要把引入的包也一起復制。

5:註解

在vue前端路由使用http.requestPut請求時,後端controller也要使用相應的@PutMapping註解

6:mybatis與mapper映射文件

在mapper.xml映射文件中使用註釋會報錯。

7:對象保存方法

//更新課程營銷信息
    public CourseMarket  updateCourseMarket(String id,CourseMarket courseMarket){
        CourseMarket one = this.getCourseMarketById(id);
        if (one!=null){
            one.setCharge(courseMarket.getCharge());
            one.setStartTime(courseMarket.getStartTime());//課程有效期,開始時間
            one.setEndTime(courseMarket.getEndTime());//課程有效期,結束時間
            one.setPrice(courseMarket.getPrice());
            one.setQq(courseMarket.getQq());
            one.setValid(courseMarket.getValid());
            courseMarketRepository.save(one);
        }else {
            //添加課程營銷信息
            one = new CourseMarket();
            BeanUtils.copyProperties(courseMarket,one);
            //設置課程id
            one.setId(id);
            courseMarketRepository.save(one);
        }
        return one;
    }

8:打印日誌

導入日誌配置文件:logback-spring.xml

import org.slf4j.Logger;
private static final Logger LOGGER = LoggerFactory.getLogger(FileSystemService.class);
LOGGER.error("getFileById InputStream is null ,htmlFileId:{}",htmlFileId);

9:Spring註解和傳參

@GetMapping("/coursepic/list/{courseId}")//通過url傳參@PathVariable("courseId")
    public CoursePic findCoursePic(@PathVariable("courseId") String courseId) {
        return courseService.findCoursePic(courseId);
    }

    @Override
    @DeleteMapping("/coursepic/delete")//通過key—value串傳參需要使用@RequestParam("courseId")指定參數名稱
    public ResponseResult deleteCoursePic(@RequestParam("courseId") String courseId) {
        return courseService.deleteCoursePic(courseId);
    }

10:Spring Cloud引入Ribbon配合 restTemplate 實現客戶端負載均衡

Request URI does not contain a valid hostname
在使用spingcloud的微服務的時候,要記住不能使用下劃線和中劃線去代替。#(使用feign時可以使用中劃線)
spring:
  application:
    name: xc-service‐manage‐cms #指定服務名稱
    

11:response.setHeader(“Content-Type”,“text/html;charset=UTF-8”);設置無效排查

由於Nginx先請求cms的課程預覽功能得到html頁面,再解析頁面中的ssi標籤,這裏必須保證cms頁面預覽返回的
頁面的Content-Type爲text/html;charset=utf-8
    
問題:在通過response.setHeader("Content-Type","text/html;charset=UTF-8");向頁面設置時發現頁面沒有達到預期效果。

排查:通過瀏覽器查看網頁源代碼發現頁面中的ssi標籤未被解析,再通F12前端調試器,發現在響應頭
Response Headers中沒有Content-Type。由此定位到錯誤原因是response.setHeader("Content-Type","text/html;charset=UTF-8")設置沒有成功。

解決:通過瀏覽器訪問其他具有ssi標籤的顯示正常的頁面,通過F12調試發現Response Headers中存在Content-Type
經過和服務器端設置的Response Headers進行對比,發現是大小寫拼寫錯誤;改正後,還是沒有看到預期效果;
最後將顯示正常的頁面的Response Headers中的Content-Type直接複製到服務器端,頁面正常訪問,ssi標籤被解析,Response Headers中出現了服務器端設置的Content-Type。

12🐛報錯:IllegalStateException

在測試時報如下錯誤
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
以上錯誤是因爲在進行測試時在test包中建立的項目包路徑com.xuecheng.search和main包中的項目包路徑不一致。

解決:
	1:在測試時test包下的項目包路徑要和main包下的項目包路徑一致。
	2:或者在測試類上加上@ContextConfiguration註解。

13🐜:ElasticaSearch與Logstash

elastiasearch的映射文件要與logstash裏配置的xc_course_template.json映射文件保持一致,不然就會導致logstash不能同步索引

14🐝:由使用ffmpeg引起的一系列慘案

在cmd中使用如下命令時報錯:
命令1:     ffmpeg.exe ‐i lucene.avi ‐c:v libx264 ‐s 1280x720 ‐pix_fmt yuv420p ‐b:a 63k ‐b:v 753k ‐r 18 .\lucene.mp4
命令2:	ffmpeg ‐i lucene.mp4 ‐hls_time 10 ‐hls_list_size 0 ‐hls_segment_filename
./hls/lucene_%05d.ts ./hls/lucene.m3u8
控制檯報錯提示:Unable to find a suitable output format for '鈥恑' 鈥恑: Invalid argument
通過百度得知錯誤原因是由於這兩行命令是我直接從文檔裏複製粘貼到命令行的,所以導致錯誤;
遇到這個問題就是不細緻造成的,從網頁上粘貼過來命令,直接運行。(我也是這樣的~~)

其實原因很簡單,就是我們使用了破折號(–)代替來了應該使用的連字符號(-)。
睜大自己的眼睛喲!

正確命令1:	ffmpeg.exe -i lucene.avi -c:v libx264 -s 1280x720 -pix_fmt yuv420p -b:a 63k -b:v 753k -r 18 .\lucene.mp4
正確命令2:	ffmpeg -i lucene.mp4 -hls_time 10 -hls_list_size 0 -hls_segment_filename ./hls/lucene_%05d.ts ./hls/lucene.m3u8
啓示錄1:在複製粘貼命令時一定要注意其中的符號時候錯誤。
啓示錄2:在其他代碼和配置文件中是也要特別注意由符號問題引發的錯誤。

在使用第二命令時報錯:[hls @ 0000000002788480] Opening './hls/lucene_00000.ts' for writing
Could not write header for output file #0 (incorrect codec parameters ?): No suc
h file or directory
Error initializing output stream 0:0 --
[aac @ 000000000055a9c0] Qavg: 50175.703
[aac @ 000000000055a9c0] 2 frames left in the queue on closing
Conversion failed!
問題原因分析:	觀察報錯信息可以發現是因爲在根目錄沒有hls這個文件夾導致的。
問題解決: 在根目錄創建hls文件夾。
啓示錄3:在寫程序時要仔細觀察報錯信息,有很多錯誤可能就是由於路徑不存在或者路徑錯誤導致的。

15🐞:nginx訪問出現跨域問題

XMLHttpRequest cannot load http://video.xuecheng.com/video/hls/lucene.m3u8. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.xuecheng.com' is therefore not allowed access.
video.js:498 VIDEOJS: ERROR: (CODE:2 MEDIA_ERR_NETWORK) HLS playlist request error at URL: http://video.xuecheng.com/video/hls/lucene.m3u8 MediaError {code: 2, status: 0, message: "HLS playlist request error at URL: http://video.xuecheng.com/video/hls/lucene.m3u8", responseText: ""}

######錯誤寫法如下代碼,將橫槓都寫成了破折號

server {
	listen 80;
	server_name video.xuecheng.com;
	location /video {
		proxy_pass http://video_server_pool;
		add_header Access‐Control‐Allow‐Origin $origin_list;
		#add_header Access‐Control‐Allow‐Origin *;
		add_header Access‐Control‐Allow‐Credentials true;
		add_header Access‐Control‐Allow‐Methods GET;
	}
}
正確寫法如下代碼複製粘貼代碼導致的錯誤
server {
	listen 80;
	server_name video.xuecheng.com;
	location /video {
		proxy_pass http://video_server_pool;
		add_header Access-Control-Allow-Origin $origin_list;
		#add_header Access-Control-Allow-Origin *;
		add_header Access-Control-Allow-Credentials true;
		add_header Access-Control-Allow-Methods GET;
	}
}
-Control-Allow-Origin $origin_list;
		#add_header Access-Control-Allow-Origin *;
		add_header Access-Control-Allow-Credentials true;
		add_header Access-Control-Allow-Methods GET;
	}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章