Red Hat Certified Cloud-
native Developer exam
,1. Create a configuration property for the application name and inject it into a CDI
bean.
A. See the Explanation.
Answer: A
Explanation:
2. Add to application.properties: app.name=CloudNativeApp
3. Create a bean:
@ApplicationScoped
public class AppNameService {
@Inject
@ConfigProperty(name = "app.name")
as
st
String appName;
ue
sp
public String getAppName() {
re
return appName;
y
as
nt
}
gu
e
}
pr
as
m
ti
4. Inject AppNameService into a REST endpoint or another bean to use it.
úl
s
la
n
co
en
m
5. Externalize a boolean flag and use it to enable/disable a service method.
a
ex
A. See the Explanation.
su
e
Answer: A
eb
u
Explanation:
pr
-A
8
37
6. In application.properties:
X
E
s
feature.enabled=true
ca
ti
ác
pr
7. Inject the flag:
as
nt
@ApplicationScoped
gu
re
public class FeatureService {
P
@Inject
@ConfigProperty(name = "feature.enabled")
boolean enabled;
public String execute() {
return enabled ? "Feature is ON" : "Feature is OFF";
}
}
8. Use default values when a configuration property is missing.
,A. See the Explanation.
Answer: A
Explanation:
@ApplicationScoped
public class TimeoutService {
@Inject
@ConfigProperty(name = "request.timeout", defaultValue = "5000")
int timeout;
public int getTimeout() {
return timeout;
}
}
This allows your app to run even if request.timeout is not in the config file.
as
st
ue
sp
re
9. Inject a configuration property into a constructor using MicroProfile Config.
y
as
nt
A. See the Explanation.
gu
e
Answer: A
pr
as
Explanation: ti
m
@ApplicationScoped
úl
s
la
public class DatabaseService {
n
co
private final String jdbcUrl;
en
m
@Inject
a
ex
public DatabaseService(@ConfigProperty(name = "db.url") String jdbcUrl) {
su
e
this.jdbcUrl = jdbcUrl;
eb
u
}
pr
-A
public String getJdbcUrl() {
8
37
return jdbcUrl;
X
E
s
}
ca
ti
ác
}
pr
Ensure db.url is defined in application.properties.
as
nt
gu
re
P
10. Inject a property into a JAX-RS resource class.
A. See the Explanation.
Answer: A
Explanation:
@Path("/env")
public class EnvResource {
@Inject
@ConfigProperty(name = "env.type")
String envType;
@GET
, public String getEnv() {
return "Environment: " + envType;
}
}
Declare env.type=dev in application.properties.
11. Use a configuration property to control bean behavior via conditional logic.
A. See the Explanation.
Answer: A
Explanation:
12. In application.properties: logging.verbose=false
as
st
ue
sp
13. In the service:
re
@ApplicationScoped
y
as
nt
public class LoggerService {
gu
e
@Inject
pr
as
@ConfigProperty(name = "logging.verbose") ti
m
boolean verbose;
úl
s
la
public void log(String message) {
n
co
if (verbose) System.out.println("[VERBOSE] " + message);
en
m
}
a
ex
}
su
e
eb
u
pr
-A
14. Inject a list of values from a comma-separated property.
8
37
A. See the Explanation.
X
E
s
Answer: A
ca
ti
ác
Explanation:
pr
supported.locales=en,fr,de
as
nt
@ApplicationScoped
gu
re
public class LocaleService {
P
@Inject
@ConfigProperty(name = "supported.locales")
List<String> locales;
public List<String> getLocales() {
return locales;
}
}
MicroProfile config automatically converts the string to List<String>.