un travail autour de vous pouvez vous DOSGI pour charger et placer la propriété dans un Util et vous accédez à votre code Pax-CDI
DOSGI:
@Component(immediate = true, configurationPolicy = ConfigurationPolicy.REQUIRE, configurationPid = "ca.esc.pbm.frontend.security")
public class SecurityConfig{
public static final String TOKEN_SIG_SECRET = "signatureSecret";
@Activate
private void activate(BundleContext bundleContext, Map<String, ?> properties) throws Exception {
logger.info("Security Config Activated");
Properties props = new Properties();
if (properties.isEmpty()) {
throw new ComponentException("Config Properties is Empty ");
}
logger.info("Property loaded " + properties.size());
props.putAll(properties);
PropertiesUtil.setProperty(props);
System.out.println(properties);
}
}
Propriété Util
/**
* Property Util to load the *.properties form class path
*
* @version 1.0
*/
public class PropertiesUtil {
private static Map<String, String> propertiesMap;
/**
* Get the property value for the given key from the loaded property
*
* @param name
* @return String
*/
public static String getProperty(String name) {
return (String) propertiesMap.get(name);
}
/**
* Set the property value for the given key from the loaded property
*
* @param props
*/
public static void setProperty(Properties props) {
Map<String, String> propertiesMapLocal = new HashMap<String, String>();
for (Object key : props.keySet()) {
String keyStr = key.toString();
propertiesMapLocal.put(keyStr, props.getProperty(keyStr));
}
propertiesMap = propertiesMapLocal;
}
}
pax-cdi
@ApplicationScoped
@Named
public class DefaultApiImpl implements DefaultApi {
@Override
public Response login(String userAgent, String username, String password, UriInfo uriInfo) {
PropertiesUtil.getProperty(SecurityConfig.TOKEN_SIG_SECRET);
}
fichier CFG
vous pouvez avoir karaf_home/etc/ca.esc.pbm.frontend.security.cfg tenant une valeur signatureSecret = my-secret
Ces fichiers * .cfg sont généralement traités comme configurtations pour administrateur de configuration Comme vous êtes déjà en cours d'exécution dans un environnement OSGi, il est préférable de s'en tenir à la façon dont cela fonctionne, laissez simplement l'administrateur de configuration faire la configuration de votre objet CDI. Mieux vaut également demander à l'une ou l'autre des communautés concernées, comme karaf et ops4j. Les deux ont des listes de diffusion, vous obtiendrez des commentaires appropriés là-bas. –
Merci pour votre suggestion mais j'essaye de ne pas essayer de modifier la configuration existante j'essaye d'accéder au nouveau cfg ajouté à mon bundle –
La même chose s'applique à ça :) –