当前位置: 首页 > 知识库问答 >
问题:

在IntelliJ中工作的Spring Boot应用程序,但不作为Docker容器

郭远
2023-03-14

我创建了一个Spring Boot应用程序,它通过HTTP POST将一些经过分析的Twitter-stuff作为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://pbs.twimg.com/profile_images/872393691427745792/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://pbs.twimg.com/profile_images/931266152973484032/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://pbs.twimg.com/profile_images/894917277925158914/nZefv1rw_normal.jpg",
                            "statusesCount": 20263,
                            "username": "InsideEVs"
                        }
                    }
                }
                ]
        }
            ]
        }
@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”如下所示:

导入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;
    }
}
public class AnalyzedKeyword {
    private String keyword;
    private List<AnalyzedTweet> tweets;

    public AnalyzedKeyword(){}
}

AnalyzedTweet(我删除了getters和setters以使其更短):

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;
    }
}

Tweet(删除的getters/setters):

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(已删除的getter/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(){}
}
FROM openjdk:8
ADD target/report-service.jar report-service.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","report-service.jar"]
WARN 1 --- [nio-8080-exec-2] .w.s.m.s.DefaultHandlerExceptionResolver : 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]
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是否更改了请求的主体,或者为什么它不起作用?

共有1个答案

曾沛
2023-03-14

如果您的问题是因为旧的代码,那么您可以做两件事来确保生成了最新的代码

docker-compose build
docker-compose up

docker-compose up --build
 类似资料:
  • 我在Hibernate4.0.1中遇到了本地查询问题。我有查询工作在数据库控制台,但不是在应用程序。我有: 名为“case”的表有两列指向同一个表--名为“cost”的表,其列为“value”。我的查询如下所示: 有人提到,'value'不是列的专有名称。这是真的,事实上这个列不是名为'value',而是有点不同。我的严格合同禁止发布任何关于代码的信息。我必须尽可能地释义它,所以我在fly中重命名

  • 我有一个简单的应用程序,它应该根据提供的URL加载一些简单的JSP页面 http://localhost:9191/mypath/-- 在IntelliJ中使用应用程序时,上述URL按预期工作。 然而,在使用-java-jar应用程序启动应用程序时。jar——Spring。配置。位置=文件:/应用属性,它为上述所有URL返回404。 无法找出原因,如果有人能指出我可能错过的任何东西,我将不胜感激。

  • 我在多模块maven项目中遇到以下问题: 该项目最初是在Eclipse中创建的,可以在那里编译和运行。它也可以用构建。 现在,当我使用以下导入选项将项目导入Intellij时,将识别父pom.xml,并导入项目及其模块。 一切看起来都很好,但是当我试图编译它时,一个类,它有一个来自另一个模块的类作为依赖项,找不到。 我尝试了很多解决方案,唯一对我有效的是过时的maven idea插件。现在,每当任

  • 我在WebSphere控制台上部署了WAR文件,并将其映射到数据源。我能够测试我用PostgreSQL服务器详细信息配置的数据源。但是我的应用程序没有连接到服务器。我是新来的WebSphere,谁能帮我配置基于下面context.xml文件的数据源。我的应用程序在tomcat中工作得很好,但在WebSphere中却不行。 我认为我在数据源配置中做错了什么。

  • 我正在使用maven,Eclipse。从Eclipse运行时一切都很好。但同样,如果部署在tomcat上,则返回http状态404。日志显示在类路径上未检测到Spring WebApplicationInitializer类型,但我正在使用web.xml。 如果有人能帮忙,我不知道这里有什么问题。筛选器和servlet映射没有问题。 securityFilter org.SpringFramewo

  • 这就是我正在做的。 部署此应用程序在 jboss 中失败,因为它在 tomcat 中部署,并且像 charm 一样工作。 我使用来自eclipse的动态web应用程序作为项目源。 将项目导出到war文件并在jboss服务器中部署也不起作用。 web.xml: Spring.xml: 控制器: 和 JBOSS 中的错误: