Skip to content

Commit

Permalink
fix default property file loading
Browse files Browse the repository at this point in the history
  • Loading branch information
HomeOfTheWizard committed Jul 13, 2024
1 parent 5b3ffdf commit 1876640
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import org.apache.maven.plugins.annotations.Mojo;
import com.homeofthewizard.SpringBootPlugin;
import com.homeofthewizard.friends.MyHelloer;
import com.homeofthewizard.plugin.MyConfiguration;
import com.homeofthewizard.friends.MySpringConfiguration;

import javax.inject.Inject;

@Mojo(name = "run", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
@SpringBootPlugin(MyConfiguration.class)
@SpringBootPlugin(MySpringConfiguration.class)
public class MyMojo extends AbstractMojo {

private final MyHelloer myFriend;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,40 @@
import org.springframework.guice.module.SpringModule;

import javax.inject.Named;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

@Named
class AnnotationBasedConfigurableSpringModule extends SpringModule {

private static final ClassLoader classLoader = AnnotationBasedConfigurableSpringModule.class.getClassLoader();

public AnnotationBasedConfigurableSpringModule()
throws ClassNotFoundException {
super(new SpringApplicationBuilder()
.resourceLoader(new DefaultResourceLoader(AnnotationBasedConfigurableSpringModule.class.getClassLoader()))
.resourceLoader(new DefaultResourceLoader())
.sources(loadSpringConfigClass())
.properties(loadApplicationProperties())
.run());
}

static private Properties loadApplicationProperties() {
var properties = new Properties();
try(var inputStream = classLoader.getResourceAsStream("application.properties")) {
if(inputStream != null){
properties.load(inputStream);
return properties;
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return properties;
}

static private Class<?>[] loadSpringConfigClass()
throws ClassNotFoundException {
var classLoader = AnnotationBasedConfigurableSpringModule.class.getClassLoader();
List<String> names = SpringFactoriesLoader.loadFactoryNames(SpringBootPlugin.class, classLoader);
List<Class<?>> types = new ArrayList<>();
for (String name : names) {
Expand Down

0 comments on commit 1876640

Please sign in to comment.