question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@ServletComponentScan in Spring Boot app does not respect custom ServletContextListener

See original GitHub issue

The Slack SDK version

+--- com.slack.api:bolt-servlet:1.18.0
|    +--- com.slack.api:slack-api-model:1.18.0
|    +--- com.slack.api:slack-api-client:1.18.0
|    |    +--- com.slack.api:slack-api-model:1.18.0 (*)
|    +--- com.slack.api:slack-app-backend:1.18.0
|    |    +--- com.slack.api:slack-api-model:1.18.0 (*)
|    |    +--- com.slack.api:slack-api-client:1.18.0 (*)
|    \--- com.slack.api:bolt:1.18.0
|         +--- com.slack.api:slack-api-model:1.18.0 (*)
|         +--- com.slack.api:slack-api-client:1.18.0 (*)
|         \--- com.slack.api:slack-app-backend:1.18.0 (*)
+--- com.slack.api:bolt-servlet:1.18.0 (n)
+--- com.slack.api:bolt-servlet:1.18.0
|    +--- com.slack.api:slack-api-model:1.18.0
|    +--- com.slack.api:slack-api-client:1.18.0
|    |    +--- com.slack.api:slack-api-model:1.18.0 (*)
|    +--- com.slack.api:slack-app-backend:1.18.0
|    |    +--- com.slack.api:slack-api-model:1.18.0 (*)
|    |    +--- com.slack.api:slack-api-client:1.18.0 (*)
|    \--- com.slack.api:bolt:1.18.0
|         +--- com.slack.api:slack-api-model:1.18.0 (*)
|         +--- com.slack.api:slack-api-client:1.18.0 (*)
|         \--- com.slack.api:slack-app-backend:1.18.0 (*)
+--- com.slack.api:bolt-servlet:1.18.0
|    +--- com.slack.api:slack-api-model:1.18.0
|    +--- com.slack.api:slack-api-client:1.18.0
|    |    +--- com.slack.api:slack-api-model:1.18.0 (*)
|    +--- com.slack.api:slack-app-backend:1.18.0
|    |    +--- com.slack.api:slack-api-model:1.18.0 (*)
|    |    +--- com.slack.api:slack-api-client:1.18.0 (*)
|    \--- com.slack.api:bolt:1.18.0
|         +--- com.slack.api:slack-api-model:1.18.0 (*)
|         +--- com.slack.api:slack-api-client:1.18.0 (*)
|         \--- com.slack.api:slack-app-backend:1.18.0 (*)
+--- com.slack.api:bolt-servlet:1.18.0
|    +--- com.slack.api:slack-api-model:1.18.0
|    +--- com.slack.api:slack-api-client:1.18.0
|    |    +--- com.slack.api:slack-api-model:1.18.0 (*)
|    +--- com.slack.api:slack-app-backend:1.18.0
|    |    +--- com.slack.api:slack-api-model:1.18.0 (*)
|    |    +--- com.slack.api:slack-api-client:1.18.0 (*)
|    \--- com.slack.api:bolt:1.18.0
|         +--- com.slack.api:slack-api-model:1.18.0 (*)
|         +--- com.slack.api:slack-api-client:1.18.0 (*)
|         \--- com.slack.api:slack-app-backend:1.18.0 (*)
+--- com.slack.api:bolt-servlet:1.18.0
|    +--- com.slack.api:slack-api-model:1.18.0
|    +--- com.slack.api:slack-api-client:1.18.0
|    |    +--- com.slack.api:slack-api-model:1.18.0 (*)
|    +--- com.slack.api:slack-app-backend:1.18.0
|    |    +--- com.slack.api:slack-api-model:1.18.0 (*)
|    |    +--- com.slack.api:slack-api-client:1.18.0 (*)
|    \--- com.slack.api:bolt:1.18.0
|         +--- com.slack.api:slack-api-model:1.18.0 (*)
|         +--- com.slack.api:slack-api-client:1.18.0 (*)
|         \--- com.slack.api:slack-app-backend:1.18.0 (*)

Java Runtime version

openjdk version “15.0.2” 2021-01-19

OS info

ProductName: macOS ProductVersion: 12.2 BuildVersion: 21D49 Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_X86_64

Steps to reproduce:

I’m trying to make a bot that will be connected to a DataBase in GCP. The connection is set up through a private IP. For this reason I’m Implementing this class:

@WebListener("Creates a connection pool that is stored in the Servlet's context for later use.")
public class ConnectionPoolContextListener implements ServletContextListener {

But I’m getting the following error when the application is trying to connect to that database. java.sql.SQLNonTransientConnectionException: Cannot connect to MySQL server on localhost:3,306. Make sure that there is a MySQL server running on the machine/port you are trying to connect to and that the machine this software is running on is able to connect to this host/port (i.e. not firewalled). Also make sure that the server has not been started with the --skip-networking flag.

The curious part of this error is if I don’t use the @ServletComponentScan in my main class SlackBotApplication. (as the documentation suggest it) it won’t fail. It will connect to my database but the slack endpoint won’t be load.

I know that this issue is not 100% related to slack but I’ve been spending two days trying to solve it, I check my database, my credentials and everything is fine, on the past I connected a database with a spring boot application using that code and everything is fine, the only difference is that I didn’t use bolt and @ServletComponentScan annotation.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ManuelG28commented, Mar 3, 2022

Np, @filmaj . Thank you for your reply, I’ll wait! 👍🏻

0reactions
seratchcommented, Mar 4, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

The @ServletComponentScan Annotation in Spring Boot
In this article, we'll go through the new @ServletComponentScan annotation in Spring Boot. The aim is to support the following Servlet 3.0 ...
Read more >
73. Embedded servlet containers - Spring
There are two ways to add Servlet , Filter , ServletContextListener and the other listeners supported by the Servlet spec to your application....
Read more >
How to register ServletContextListener in spring boot
I have one listener public class ExecutorListener implements ServletContextListener . How can I register this listener for Spring Boot? I've ...
Read more >
The @ServletComponentScan Annotation in Spring Boot
In this post, we will explore the @ServletComponentScan annotation in Spring Boot. Spring Boot provides several annotations for easy use and ...
Read more >
Spring Boot Reference Guide
Custom JSON Serializers and Deserializers . ... You do not need to use the CLI to work with Spring Boot, but it is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found