Close
« Tutorial

Spring MVC - Active Profiles in Java Code MCQ

0/13
0 ✓
0 ✗

1. How can we set the active profile in Java code instead of using web.xml?

2. Which init parameter name is used to set the active profiles?

3. Which method of an initializer class do we override to set the profile parameter?

4. Which method call sets the active profile to dev?

public void onStartup(ServletContext ctx)
        throws ServletException {
    ctx.______("spring.profiles.active", "dev");
}

5. A bean is annotated with @Profile("default"). When is this bean created?

6. Which annotation makes this bean available only when the dev profile is active?

@Service
public class DevMailSender
        implements MailSender {
}

7. A controller returns the message of the injected Msg bean. What does a request to / return?

@Service
@Profile("default")
class LocalMsg implements Msg {
    public String get() { return "local"; }
}

@Service
@Profile("prod")
class ProdMsg implements Msg {
    public String get() { return "prod"; }
}

public void onStartup(ServletContext ctx)
        throws ServletException {
    ctx.setInitParameter(
            "spring.profiles.active", "prod");
}
Join