This commit is contained in:
Francesco 2023-09-21 15:38:50 +02:00
parent f83adbf601
commit cad093899a
3 changed files with 17 additions and 20 deletions

View File

@ -17,34 +17,26 @@ broken, please report it as an issue and I will try to take a look at it.
<dependency>
<groupId>tech.ailef</groupId>
<artifactId>spring-boot-db-admin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.3</version>
</dependency>
```
2. A few configuration steps are required on your code in order to integrate the library in your project. If you don't want
2. A few simple configuration steps are required on your end in order to integrate the library into your project. If you don't want
to test on your own code, you can clone the [test project](https://github.com/aileftech/spring-boot-database-admin-test) which provides
a sample database and already configured code.
If you wish to integrate it into your project instead, the first step is create creating a configuration class:
If you wish to integrate it into your project instead, the first step is adding these to your `application.properties` file:
```
@DbAdminConfiguration
@Configuration
public class TestConfiguration implements DbAdminAppConfiguration {
@Override
public String getModelsPackage() {
return "your.models.package"; // The package where your @Entity classes are located
}
}
dbadmin.enabled=true # Optional, default true
dbadmin.baseUrl=admin # The first-level part of the URL path: http://localhost:8080/${baseUrl}/
dbadmin.modelsPackage=tech.ailef.dbadmin.test.models # The package that contains your @Entity classes
```
The last step is to annotate your `@SpringBootApplication` class containing the `main` method with the following:
```
@ComponentScan(basePackages = {"your.project.root.package", "tech.ailef.dbadmin"})
@EnableJpaRepositories(basePackages = {"your.project.root.package", "tech.ailef.dbadmin"})
@EntityScan(basePackages = {"your.project.root.package", "tech.ailef.dbadmin"})
@ImportAutoConfiguration(DbAdminAutoConfiguration.class)
```
This tells Spring to scan the `tech.ailef.dbadmin` packages and look for components there as well. Remember to also include

View File

@ -7,9 +7,12 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.stereotype.Component;
@ -43,7 +46,7 @@ import tech.ailef.dbadmin.misc.Utils;
*/
@Component
public class DbAdmin {
private DbAdminProperties properties;
private static final Logger logger = Logger.getLogger(DbAdmin.class.getName());
@PersistenceContext
private EntityManager entityManager;
@ -53,7 +56,6 @@ public class DbAdmin {
private String modelsPackage;
public DbAdmin(@Autowired EntityManager entityManager, @Autowired DbAdminProperties properties) {
this.properties = properties;
this.modelsPackage = properties.getModelsPackage();
this.entityManager = entityManager;
@ -64,6 +66,8 @@ public class DbAdmin {
for (BeanDefinition bd : beanDefs) {
schemas.add(processBeanDefinition(bd));
}
logger.info("Spring Boot Database Admin initialized. Loaded " + schemas.size() + " table definitions");
logger.info("Spring Boot Database Admin web interface at: http://YOUR_HOST:YOUR_PORT/" + properties.getBaseUrl());
}
/**

View File

@ -1,13 +1,14 @@
package tech.ailef.dbadmin;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
//@ConditionalOnProperty(name = "crudadmin.enabled", matchIfMissing = true)
@ConditionalOnProperty(name = "dbadmin.enabled", matchIfMissing = true)
@ComponentScan
@EnableConfigurationProperties(DbAdminProperties.class)
@Configuration
@AutoConfiguration
public class DbAdminAutoConfiguration {
}