Skip to content

Commit

Permalink
Using @PostConstruct to create mandatory directories
Browse files Browse the repository at this point in the history
  • Loading branch information
isontheline committed May 28, 2024
1 parent 0d82ef6 commit dd50479
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,28 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import ai.dragon.properties.DataProperties;
import jakarta.annotation.PostConstruct;
import lombok.Getter;

@Component
@Order(1)
public class DirectoryStructureComponent implements CommandLineRunner {
@Order(Ordered.HIGHEST_PRECEDENCE)
public class DirectoryStructureComponent {
private final Logger logger = LoggerFactory.getLogger(this.getClass());

@Autowired
private DataProperties dataProperties;

@Getter
private File dataDirectory;

public DirectoryStructureComponent(DataProperties dataProperties) {
this.dataProperties = dataProperties;
}

@Override
public void run(String... args) throws Exception {
@PostConstruct
private void postConstruct() throws Exception {
dataDirectory = createDataDirectories();
createDatabaseDirectory();
}
Expand Down
4 changes: 0 additions & 4 deletions backend/src/main/java/ai/dragon/config/AppConfig.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package ai.dragon.config;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import ai.dragon.properties.DataProperties;

@Configuration
@EnableConfigurationProperties(DataProperties.class)
public class AppConfig {
}
16 changes: 16 additions & 0 deletions backend/src/main/java/ai/dragon/config/PropertiesConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ai.dragon.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import ai.dragon.properties.DataProperties;

@Configuration
public class PropertiesConfig {
@Bean
@ConfigurationProperties(prefix = DataProperties.PREFIX)
public DataProperties dataProperties() {
return new DataProperties();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package ai.dragon.properties;

import org.springframework.boot.context.properties.ConfigurationProperties;

import lombok.Getter;
import lombok.Setter;

@ConfigurationProperties(prefix = DataProperties.PREFIX)
@Getter
@Setter
public class DataProperties {
Expand Down

0 comments on commit dd50479

Please sign in to comment.