Created
April 15, 2014 04:12
-
-
Save malkusch/10701484 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | |
import org.springframework.context.annotation.ComponentScan; | |
import org.springframework.context.annotation.Lazy; | |
import org.springframework.context.annotation.Scope; | |
import org.springframework.stereotype.Component; | |
import org.springframework.stereotype.Controller; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.ResponseBody; | |
import org.springframework.web.context.WebApplicationContext; | |
@Controller | |
@EnableAutoConfiguration | |
@ComponentScan(basePackageClasses = SSCCE.class) | |
public class SSCCE { | |
@Autowired | |
@Lazy | |
private SingletonBean bean; | |
@Component | |
@Lazy | |
public static class SingletonBean { | |
@Autowired | |
private RequestBean bean; | |
@Override | |
public String toString() { | |
return super.toString() + bean.toString(); | |
} | |
} | |
@Component | |
@Scope(WebApplicationContext.SCOPE_REQUEST) | |
public static class RequestBean { | |
@Override | |
public String toString() { | |
return super.toString(); | |
} | |
} | |
@RequestMapping("/") | |
@ResponseBody | |
String home() { | |
return bean.toString(); | |
} | |
public static void main(String[] args) throws Exception { | |
SpringApplication.run(SSCCE.class, args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment