Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a web application running in Tomcat and using Spring MVC to define controllers and mappings. I have the following class:

@Controller("api.test")
public class TestController {

        @RequestMapping(value = "/test", method = RequestMethod.GET)   
        public @ResponseBody String test(HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
            // body
        }
}

I would like to make this controller and the ".../test" path available according to a property defined somewhere (e.g. file). If the property is, lets say, false, I would like the app to behave as if that path doesn't exist and if it is true, to behave normally. How can I do this? Thanks.

share|improve this question

1 Answer

up vote 2 down vote accepted

If you are using Spring 3.1+, make the controller available only in the test profile:

@Profile("test")
class TestController {
    ...
}

then enable that profile by e.g. passing the following system property at Tomcat boot:

-Dspring.profiles.active=test

To disable the controller simply omit the given profile.

share|improve this answer
Yes, this works fine. Thanks. – Phykus Green yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.