javajerseyconfigdeltaspike

Error while injecting deltaspike properties


I am following an example for deltaspike config on github. I keep getting this exception:

org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at
SystemInjecteeImpl(requiredType=String,parent=AntivaxParentController,qualifiers=
{@org.apache.deltaspike.core.api.config.ConfigProperty(parameterizedBy=org.apache.deltaspike.NullValueMarker, 
defaultValue=null, projectStageAware=true, evaluateVariables=true, 
converter=interface org.apache.deltaspike.core.api.config.ConfigResolver$Converter, 
name=antivax.parents.intelligence)},position=-1,optional=false,self=false,unqualified=null,1961437149)

I have added a custom config source provider to load properties from a specific location:

public class MyConfigSourceProvider implements ConfigSourceProvider {
    @Override
    public List<ConfigSource> getConfigSources() {
        return Arrays.asList((ConfigSource) new MyConfigSource());
    }
}

The implementation of MyConfigSource is:

public class MyConfigSource extends BaseConfigSource {
    
    private final Properties properties;
    private static final String MY_CONF_FILE_NAME = "G:\\antivax-config.properties";
    
    public MyConfigSource() {
        
        properties = new Properties();
        try (InputStream inStream = new FileInputStream(MY_CONF_FILE_NAME)) {
            properties.load(inStream);
        } catch (Exception e) { }
    }

    @Override
    public String getConfigName() {
        return MY_CONF_FILE_NAME;
    }

    @Override
    public int getOrdinal() {
        return 401;
    }

    @Override
    public Map<String, String> getProperties() {
        Map<String, String> propertyMap = new HashMap<>();
        properties.keySet().stream().map(Objects::toString).forEach(key -> propertyMap.put(key, (String)properties.get(key)));
        return propertyMap;
    }

    @Override
    public String getPropertyValue(String key) {
        return properties.getProperty(key);
    }

    @Override
    public boolean isScannable() {
        return false;
    }

}

However, this fails..

@Path("parents")
@RequestScoped
public class AntivaxParentController {

    @Inject
    @ConfigProperty(defaultValue = "hello world", name = "antivax.parents.intelligence")
    private String intelligence;

    @GET
    @Path("ping")
    @Produces(MediaType.APPLICATION_JSON)
    public Response givePing() {
        return Response.status(Status.OK).entity(intelligence).build();
    }
}

I have tried

  1. Using default property file
  2. Using a custom property file

I have uploaded the project here. Any leads appreciated.

Update: I removed the annotations on String and checked the output of System.out.println(ConfigResolver.getAllProperties(). All the properties in the property file are loaded. The error appears on using @Inject and @ConfigProperty on the String.


Solution

  • Returning true from the overridden method isScannable made the difference.