Skip to content

Instantly share code, notes, and snippets.

@malkusch
Created April 15, 2014 03:37
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/10700114 to your computer and use it in GitHub Desktop.
Save malkusch/10700114 to your computer and use it in GitHub Desktop.
import javax.servlet.http.HttpServletRequest;
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.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
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)
@Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
public class SSCCE {
@Autowired
private RequestBean bean;
@Component
@Scope(WebApplicationContext.SCOPE_REQUEST)
public static class RequestBean {
@Autowired
private HttpServletRequest request;
@Override
public String toString() {
return super.toString() + request.toString();
}
}
@RequestMapping("/")
@ResponseBody
String home() {
return bean.toString();
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SSCCE.class, args);
}
}
@malkusch
Copy link
Author

Use spring-boot for that SSCCE:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.0.1.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment