Close
« Tutorial

Spring MVC - Setting Active Profile in web.xml MCQ

0/13
0 ✓
0 ✗

1. In a servlet based Spring MVC application, which file is used to set the active profile with a context-param?

2. Which web.xml entry makes dev the active profile?

3. The web.xml sets spring.profiles.active to dev. What is the response of a GET request to /?

public interface Greeting {
    String msg();

    @Service
    @Profile("default")
    class Local implements Greeting {
        public String msg() {
            return "local";
        }
    }

    @Service
    @Profile("dev")
    class Dev implements Greeting {
        public String msg() {
            return "dev";
        }
    }
}

@Controller
public class HomeController {
    @Autowired
    private Greeting greeting;

    @GetMapping("/")
    @ResponseBody
    public String handle() {
        return greeting.msg();
    }
}

4. Which annotation should be added to this class so that it is used only when the prod profile is active?

@Service
// Add annotation here
public class ProdGreeting
        implements Greeting {

    public String msg() {
        return "prod";
    }
}

5. No active profile is set in web.xml. Which profile does Spring use?

6. The active profile is prod. What happens to a bean marked with @Profile("dev")?

Join