rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.68k stars 1.18k forks source link

Spring Boot problem #484

Closed vrepetenko closed 6 years ago

vrepetenko commented 6 years ago

Hi!

Trying to run simple bot using Spring Boot, and get error: aused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'polzaTelegramBot': Invocation of init method failed; nested exception is com.google.inject.ConfigurationException: Guice configuration errors:

1) No implementation for org.telegram.telegrambots.generics.BotSession was bound. while locating org.telegram.telegrambots.generics.BotSession

1 error Caused by: com.google.inject.ConfigurationException: Guice configuration errors:

1) No implementation for org.telegram.telegrambots.generics.BotSession was bound. while locating org.telegram.telegrambots.generics.BotSession

1 error

@SpringBootApplication
@EnableTelegramBots
public class Application {

    public static void main(String[] args) {
        ApiContextInitializer.init();
        SpringApplication.run(Application.class, args);
    }
}
@Component
public class SimpleTelegramBot extends TelegramLongPollingBot {

    private static final Logger logger = LoggerFactory.getLogger(SimpleTelegramBot.class);

    @PostConstruct
    public void registerBot(){
         TelegramBotsApi telegramBotsApi = new TelegramBotsApi();
         try {
           telegramBotsApi.registerBot(this);
         } catch (TelegramApiException e) {
           logger.error(e.toString());
         }
    }

    @Override
    public void onUpdateReceived(Update update) {
        Message message = update.getMessage();
......
       }
}
vrepetenko commented 6 years ago

It seems network related problem...

rubenlagus commented 6 years ago

@vrepetenko if it is a network problem, can you close the issue?

coffman21 commented 5 years ago

@vrepetenko How did you get rid of this issue? It doesn't seems like network issue: I am able to establish connection with SOCKS5 server, but still getting issue with unbounded BotSession. UPD: found resolution here

Try moving ApiContextInitializer.init(); to a static {} block. Or put it somewhere to run earlier.