春季启动应用程序工作在IntelliJ,但不是作为docker集装箱

我已经创build了一个Spring启动应用程序,它通过HTTP Post将一些Twitter的内容分析为JSON对象。 JSON对象如下所示:

{ "analyzedKeywords": [ { "keyword": "VW", "tweets": [ { "indicoScore": 0.8174982823, "popularity": 5659, "tweet": { "createdAt": 1512660826000, "favouriteCount": 0, "retweet": true, "retweetCount": 5, "retweetedStatus": { "createdAt": 1512660253000, "favouriteCount": 1, "retweet": false, "retweetCount": 5, "retweetedStatus": null, "tweetText": "No time for twitter drama because those VW Polo's aren't gonna strip themselves", "user": { "email": null, "favouritesCount": 1154, "followersCount": 1080, "friendsCount": 295, "id": 197398224, "profileImageURL": "http://img.gdocker.com/json/8DhxJY5-_normal.jpg", "statusesCount": 120014, "username": "Kabelo" } }, "tweetText": "No time for twitter drama because those VW Polo's aren't gonna strip themselves ", "user": { "email": null, "favouritesCount": 9820, "followersCount": 5654, "friendsCount": 558, "id": 58419134, "profileImageURL": "http://pbs.twimg.com/profile_images/936993708142157825/BgvNafEp_normal.jpg", "statusesCount": 124848, "username": "\ud83c\udf93 Mmina T\u0161hipi \ud83c\udf93" } } } ] }, { "keyword": "Tesla", "tweets": [ { "indicoScore": 0.9143414881, "popularity": 10027, "tweet": { "createdAt": 1512660797000, "favouriteCount": 0, "retweet": true, "retweetCount": 4, "retweetedStatus": { "createdAt": 1512602297000, "favouriteCount": 5, "retweet": false, "retweetCount": 4, "retweetedStatus": null, "tweetText": "Anyone know of a plug-in vehicle that can seat 6 and, preferably, tow? \nSo far, our list includes the @Tesla Model\u2026 ", "user": { "email": null, "favouritesCount": 28, "followersCount": 39, "friendsCount": 13, "id": 930140890189975553, "profileImageURL": "http://img.gdocker.com/json/I6PltHR1_normal.jpg", "statusesCount": 32, "username": "InsideEVs Forum" } }, "tweetText": "Anyone know of a plug-in vehicle that can seat 6 and, preferably, tow? \nSo far, our list includes the @Tesla Model\u2026 ", "user": { "email": null, "favouritesCount": 6, "followersCount": 10023, "friendsCount": 18, "id": 568621669, "profileImageURL": "http://img.gdocker.com/json/nZefv1rw_normal.jpg", "statusesCount": 20263, "username": "InsideEVs" } } } ] } ] } 

获取JSON的方法如下所示:

 @RequestMapping(method = RequestMethod.POST, consumes = "application/json") public ResponseEntity<byte[]> Post(@RequestBody AnalyzedKeywordList analyzedKeywords) { Document document = new Document(); PdfWriter writer = null; ... 

当我从IntelliJ运行我的代码并将这个JSON发送到我的服务时,AnalyzedKeyWordList被关键字对象“VW”和“TESLA”填充。 所以它的工作。

类“AnalyzedKeywordList”看起来像这样:

import java.util.List;

 public class AnalyzedKeywordList { List<AnalyzedKeyword> analyzedKeywords; public AnalyzedKeywordList(List<AnalyzedKeyword> analyzedKeywords) { this.analyzedKeywords = analyzedKeywords; } public AnalyzedKeywordList(){} public List<AnalyzedKeyword> getAnalyzedKeywords() { return analyzedKeywords; } public void setAnalyzedKeywords(List<AnalyzedKeyword> analyzedKeywords) { this.analyzedKeywords = analyzedKeywords; } } 

AnalyzedKeyword看起来像这样(我已经删除了getters和setter使它更短):

 public class AnalyzedKeyword { private String keyword; private List<AnalyzedTweet> tweets; public AnalyzedKeyword(){} } 

AnalyzedTweet(我已经删除了getter和setter来缩短它):

 public class AnalyzedTweet { private float indicoScore; private Tweet tweet; private float popularity; public AnalyzedTweet(){} public AnalyzedTweet(float indicoScore, Tweet tweet, float popularity) { this.indicoScore = indicoScore; this.tweet = tweet; this.popularity = popularity; } } 

鸣叫(删除获得者/设置者):

 public class Tweet { private String tweetText; private boolean isRetweet; private Date createdAt; private float favouriteCount; private float retweetCount; private Tweet retweetedStatus; private TwitterUser user; public Tweet(){} } 

TwitterUser(删除getters / setters):

 public class TwitterUser { private long id; private String username; private String email; private String profileImageURL; private float followersCount; private float friendsCount; private float favouritesCount; private float statusesCount; public TwitterUser(){} } 

现在我正在编译一个.jar文件,并使用docker来编写它(以及其他一些服务):

 FROM openjdk:8 ADD target/report-service.jar report-service.jar EXPOSE 8080 ENTRYPOINT ["java","-jar","report-service.jar"] 

在启动Docker容器之后,我再次发送完全相同的Post请求到在Docker容器中运行的Spring启动服务,但是它失败了,

 WARN 1 --- [nio-8080-exec-2] .wsmsDefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token report-service_1 | at [Source: java.io.PushbackInputStream@4086f71a; line: 3, column: 1] 

我通过“docker-compose up”开始我的Docker容器。 这也创造了一些其他容器工作正常。

 version: '3' services: twitter-service: build: ./twitter ports: - "5000:8080" analyse-service: build: ./analysis_py volumes: - ./analysis_py:/usr/src/app ports: - "5001:80" report-service: build: ./report ports: - "5002:8080" frontend: build: ./frontend # specify the directory of the Dockerfile #volumes: # - ./frontend:/usr/src/app ports: - "4200:4200" 

docker工更改请求的主体或为什么不工作?

我find了解决我的问题的方法。 我的代码工作正常,但似乎在运行命令时,Docker虚拟机没有更新

 docker-compose up 

我的Spring Boot应用程序的旧版本被部署,而不是新版本。 当我closuresDocker时,删除了虚拟机并运行了上面的命令,Docker创build了一个新的虚拟机并且工作起来非常完美。

我不知道为什么发生这种情况,因为Docker文档指出 :

如果存在服务的容器,并且在创build容器后服务的configuration或映像已更改,则docker-compose将通过停止并重新创build容器(保留已装入的卷)来提取更改。

如果你的问题是由于旧代码,那么你可以做两件事情,以确保你得到最新的代码build立

 docker-compose build docker-compose up 

要么

 docker-compose up --build