Bael 5543 - Running a spring boot app without DB (#12339)

* 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 <Abhinav2.Pandey@airtel.com>
This commit is contained in:
Abhinav Pandey 2022-06-16 12:58:07 +05:30 committed by GitHub
parent 405578bfb5
commit a5ddb7dd9c
6 changed files with 93 additions and 0 deletions

View File

@ -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>

View File

@ -0,0 +1 @@
### Relevant Articles:

View File

@ -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>

View File

@ -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);
}
}

View File

@ -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

View File

@ -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);
}
}