Closed ttashmatov closed 6 years ago
Where do you added ApiContextInitializer.init();
?
https://github.com/rubenlagus/TelegramBots/wiki/How-To-Update#to-version-242
Duplicate of #161, #277, #167 an #234
public static void main(String[] args) throws SQLException {
ApiContextInitializer.init();
TelegramBotsApi telegramBotsApi = new TelegramBotsApi();
......
Creating project with Gradle
I am currently experiencing this issue too, i use springboot as well. I tried all the work around in the comments but no luck. has anyone solved this.
@charmstead I can share my implementation with Spring.
@maystrovyy please do share your implementation so that others can learn from it.
I realized the reason for that issue. The problem is that you create Bot instance before ApiContextInitializer.init();
The INJECTOR
in org.telegram.telegrambots.ApiContext
register beans only once while initialization.
In my case I have a configuration like this:
@Bean
FilaBot bot() {
return new FilaBot() {
@Override
public String getBotToken() {
return token;
}
@Override
public String getBotUsername() {
return username;
}
};
}
@Bean(initMethod = "init", destroyMethod = "dispose")
BotService botService() {
ApiContextInitializer.init();
return new BotService(new TelegramBotsApi(), bot());
}
Spring construct bot
bean first, and INJECTOR
initialize without any beans. And org.telegram.telegrambots.ApiContext
simply do nothing instead of adding beans to internal map.
The solution is calling ApiContextInitializer.init();
before all initiations (bots and api). In my case I do workaround moving bot
bean definition after botService
bean. Like this:
@Bean(initMethod = "init", destroyMethod = "dispose")
BotService botService() {
ApiContextInitializer.init();
return new BotService(new TelegramBotsApi(), bot());
}
@Bean
FilaBot bot() {
return new FilaBot() {
@Override
public String getBotToken() {
return token;
}
@Override
public String getBotUsername() {
return username;
}
};
}
Hope developers will fix that issue in a proper way
So documentation https://github.com/rubenlagus/TelegramBots/wiki/How-To-Update#to-version-242 also have an issue:
2. At the beginning of your program (before creating your TelegramBotsApi instance, add the following line:
should be
I need to start config bot with my application When I start my application then i have this error
I add
ApiContextInitializer.init();
in static method, but the problem did not disappear