Skip to content

Instantly share code, notes, and snippets.

@malkusch
Created April 15, 2014 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malkusch/10701484 to your computer and use it in GitHub Desktop.
Save malkusch/10701484 to your computer and use it in GitHub Desktop.
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