Skip to content

Commit

Permalink
Bael 5543 - Running a spring boot app without DB (eugenp#12339)
Browse files Browse the repository at this point in the history
* BAEL-5543 - Running a spring boot app without db

* BAEL-5543 - Adding authentication properties

* BAEL-5543 - Moving to a new module

* BAEL-5543 - Changing test class name

* BAEL-5543 - Reducing Java version

Co-authored-by: Abhinav Pandey <[email protected]>
  • Loading branch information
abh1navv and Abhinav Pandey authored Jun 16, 2022
1 parent 935da52 commit 40b66b1
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions spring-boot-modules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<module>spring-boot-actuator</module>
<module>spring-boot-data-2</module>
<module>spring-boot-validation</module>
<module>spring-boot-data-3</module>
</modules>

<dependencyManagement>
Expand Down
1 change: 1 addition & 0 deletions spring-boot-modules/spring-boot-data-3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
### Relevant Articles:
47 changes: 47 additions & 0 deletions spring-boot-modules/spring-boot-data-3/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>spring-boot-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>com.baeldung</groupId>
<artifactId>spring-boot-data-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-boot-data-3</name>
<description>spring-boot-data-3</description>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.baeldung.startwithoutdb;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class StartWithoutDbApplication {

public static void main(String[] args) {
SpringApplication.run(StartWithoutDbApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/myDb
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=none
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.baeldung.startwithoutdb;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;

import javax.sql.DataSource;

@SpringBootTest(classes = StartWithoutDbApplication.class)
class StartWithoutDbIntegrationTest {

@Autowired
private ApplicationContext context;

@Test
public void givenAutoConfigDisabled_whenStarting_thenNoAutoconfiguredBeansInContext() {
context.getBean(DataSource.class);
}


}

0 comments on commit 40b66b1

Please sign in to comment.