Skip to content

Commit

Permalink
Explicitly deregister JDBC driver (#181)
Browse files Browse the repository at this point in the history
* Explicitly deregister JDBC driver

* Remove first solution attempt
  • Loading branch information
mmwinther authored Jul 3, 2024
1 parent 38c6a82 commit 4ad9dc0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
20 changes: 6 additions & 14 deletions klass-forvaltning/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<!-- Potential cause of DPMETA-287 -->
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<!-- Potential cause of DPMETA-287 -->
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>

<!--VAADIN-->
Expand Down Expand Up @@ -198,6 +184,12 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>4.0.4</version>
<scope>compile</scope>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,43 @@
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Import;

// CHECKSTYLE:OFF
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletException;


@SpringBootApplication
@Import(EmbeddedServletContainerAutoConfiguration.EmbeddedTomcat.class)
public class KlassForvaltningApplication extends SpringBootServletInitializer {
// TODO kmgv if using embedded container (e.g. Tomcat) remove below method and extends SpringBootServletInitializer

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(KlassForvaltningApplication.class);
}

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
servletContext.addListener(new ServletContextListener() {

@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
// Nothing to do here
}

@Override
public void contextDestroyed(ServletContextEvent sce) {
// Explicitly deregister the driver to prevent race conditions with Tomcat de-registering the Driver.
// This is fixed in Spring Boot versions >=2.3.0
// Ref https://github.com/spring-projects/spring-boot/issues/21221
org.mariadb.jdbc.Driver.unloadDriver();
}
});
super.onStartup(servletContext);
}


public static void main(String[] args) {
SpringApplication.run(KlassForvaltningApplication.class, args);
}
}
// CHECKSTYLE:ON

0 comments on commit 4ad9dc0

Please sign in to comment.