java - 我可以从 Spring Boot 应用程序启动电报机器人吗?

标签 java spring-boot telegram-bot

我尝试从这里创建一个机器人 https://github.com/rubenlagus/TelegramBots

它作为一个简单的应用程序工作,但是当我尝试添加 Spring Boot 时它不起作用。我想这是因为 Spring Boot 启动了 Tomcat,而电报机器人试图发送/接收一些 http。

我没有收到任何错误(机器人作为 @Component bean 启动)。

是否有可能连接这种机器人和 Spring Boot 应用程序或至少是 Web 应用程序?

最佳答案

您可以尝试使用同一库中的 telegrambots-spring-boot-starter

你的主要配置应该是这样的:

@SpringBootApplication
public class YourApplicationMainClass {

    public static void main(String[] args) {
        ApiContextInitializer.init();

        SpringApplication.run(YourApplicationMainClass.class, args);
    }
}

你的机器人的类别:

// Standard Spring component annotation
@Component
public class YourBotName extends TelegramLongPollingBot {
    //Bot body.
}

您可以在此处找到更多信息 https://github.com/rubenlagus/TelegramBots/tree/master/telegrambots-spring-boot-starter

关于java - 我可以从 Spring Boot 应用程序启动电报机器人吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50490617/

相关文章:

java - 调用 Query.uniqueResult() 时出现 ClassCastException

intellij-idea - IntelliJ "Initialization failed for ' https ://start. spring.io'请检查 URL、网络和代理设置"

java - 限制显示项目的数量 :each

java - 如何更正 JSP 中的 servlet 映射?

java - AWS EC2 - java.lang.ClassNotFoundException : com. mysql.jdbc.Driver

java - 如何存储使用 hibernate 命令的 ArrayList?

java - 在后续步骤中访问资源 Spring Batch

python - 如何使用 Nginx 反向代理部署 Telegram Bot

java - 尝试实现 telegrambots-spring-boot-starter 并创建 Telegram 机器人,但它不起作用

telegram-bot - 如何小型化电报机器人按钮