I have developed a Telegram bot and I wanted it to run in Tomcat environment. I converted my java program into Spring boot project as this.
My conversion is basically adding spring boot dependency to pom,and make main class as spring boot runner. In eclipse environment, my application runs as expected. When I package it into war and deploy it into tomcat, the business logic does not run. Spring boot starts, I can see the logs of it. However telegram bot does not initialized.
I also added a dummy RestController which return “hello”. When I run localhost:8080/endpoint I can see “hello”. However, Telegram bot is not active.
In some resources, they say telegrambots-spring-boot-starter should be in the project. My telegram dependency contains it. It is not the case. I do not get any error log in catalina.out. Application just starts and stays as it is. I dont understand why.
Any help is appreciated.
2
Answers
It’s because you initialize your bot inside the main method of IftarVaktiApp. It doesn’t get called anymore because you’re not running IftarVaktiApp in it’s main method. You should use an EventListener or just implement a CommandLineRunner. see this EventListener or this CommandLineRunner and initialize your bot there.
Working with Spring Boot as (1) an enterprise application on a Tomcat server, deployed through a .WAR is different than (2) running Java code inside your own JVM machine. This means, a main method is not started magically when you deploy the .WAR on the Tomcat server. Starting a Spring Boot application through a Tomcat webserver works differently, and you should refactor the entire main method according to Spring Boot project guidelines to execute the code from the Tomcat environment.
I have cloned your project from GitHub and I can see this is not a real Spring Initializr project. If you want to run your code through Spring on Tomcat, I advise the following steps:
ps. I have not functionally checked any of your code.