Spring Boot Basic - Tag 7
← Zurück zur ÜbersichtBeschreibung des Scopes
abc123
Info wird hier angezeigt
@Service
public class SingletonService {
// Eine Instanz für die gesamte App!
private Counter counter = new Counter();
public void increment() {
counter.increment();
}
}
@Service
@Scope("prototype")
public class PrototypeService {
// Neue Instanz bei jedem getBean()!
private Counter counter = new Counter();
public void increment() {
counter.increment();
}
}
@Component
@Scope(value = WebApplicationContext.SCOPE_REQUEST,
proxyMode = ScopedProxyMode.TARGET_CLASS)
public class RequestScopedBean {
// Eine Instanz pro HTTP-Request!
private Counter counter = new Counter();
public void increment() {
counter.increment();
}
}
@Component
@Scope(value = WebApplicationContext.SCOPE_SESSION,
proxyMode = ScopedProxyMode.TARGET_CLASS)
public class SessionScopedBean {
// Eine Instanz pro User-Session!
private Counter counter = new Counter();
public void increment() {
counter.increment();
}
}
@Component
@Scope(value = WebApplicationContext.SCOPE_APPLICATION,
proxyMode = ScopedProxyMode.TARGET_CLASS)
public class ApplicationScopedBean {
// Eine Instanz für alle User!
private Counter counter = new Counter();
public void increment() {
counter.increment();
}
}