mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-06-09 05:48:20 +00:00
WIP
This commit is contained in:
parent
f83adbf601
commit
cad093899a
22
README.md
22
README.md
@ -17,34 +17,26 @@ broken, please report it as an issue and I will try to take a look at it.
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>tech.ailef</groupId>
|
<groupId>tech.ailef</groupId>
|
||||||
<artifactId>spring-boot-db-admin</artifactId>
|
<artifactId>spring-boot-db-admin</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.3</version>
|
||||||
</dependency>
|
</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
|
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.
|
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
|
dbadmin.enabled=true # Optional, default true
|
||||||
@Configuration
|
dbadmin.baseUrl=admin # The first-level part of the URL path: http://localhost:8080/${baseUrl}/
|
||||||
public class TestConfiguration implements DbAdminAppConfiguration {
|
dbadmin.modelsPackage=tech.ailef.dbadmin.test.models # The package that contains your @Entity classes
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getModelsPackage() {
|
|
||||||
return "your.models.package"; // The package where your @Entity classes are located
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The last step is to annotate your `@SpringBootApplication` class containing the `main` method with the following:
|
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"})
|
@ImportAutoConfiguration(DbAdminAutoConfiguration.class)
|
||||||
@EnableJpaRepositories(basePackages = {"your.project.root.package", "tech.ailef.dbadmin"})
|
|
||||||
@EntityScan(basePackages = {"your.project.root.package", "tech.ailef.dbadmin"})
|
|
||||||
```
|
```
|
||||||
|
|
||||||
This tells Spring to scan the `tech.ailef.dbadmin` packages and look for components there as well. Remember to also include
|
This tells Spring to scan the `tech.ailef.dbadmin` packages and look for components there as well. Remember to also include
|
||||||
|
@ -7,9 +7,12 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
|
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||||
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
||||||
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@ -43,7 +46,7 @@ import tech.ailef.dbadmin.misc.Utils;
|
|||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class DbAdmin {
|
public class DbAdmin {
|
||||||
private DbAdminProperties properties;
|
private static final Logger logger = Logger.getLogger(DbAdmin.class.getName());
|
||||||
|
|
||||||
@PersistenceContext
|
@PersistenceContext
|
||||||
private EntityManager entityManager;
|
private EntityManager entityManager;
|
||||||
@ -53,7 +56,6 @@ public class DbAdmin {
|
|||||||
private String modelsPackage;
|
private String modelsPackage;
|
||||||
|
|
||||||
public DbAdmin(@Autowired EntityManager entityManager, @Autowired DbAdminProperties properties) {
|
public DbAdmin(@Autowired EntityManager entityManager, @Autowired DbAdminProperties properties) {
|
||||||
this.properties = properties;
|
|
||||||
this.modelsPackage = properties.getModelsPackage();
|
this.modelsPackage = properties.getModelsPackage();
|
||||||
this.entityManager = entityManager;
|
this.entityManager = entityManager;
|
||||||
|
|
||||||
@ -64,6 +66,8 @@ public class DbAdmin {
|
|||||||
for (BeanDefinition bd : beanDefs) {
|
for (BeanDefinition bd : beanDefs) {
|
||||||
schemas.add(processBeanDefinition(bd));
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package tech.ailef.dbadmin;
|
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.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
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
|
@ComponentScan
|
||||||
@EnableConfigurationProperties(DbAdminProperties.class)
|
@EnableConfigurationProperties(DbAdminProperties.class)
|
||||||
@Configuration
|
@AutoConfiguration
|
||||||
public class DbAdminAutoConfiguration {
|
public class DbAdminAutoConfiguration {
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user