How to register custom scope in Spring Boot?

3.2k Views Asked by At

I'm trying to register a custom scope to incorporate a third party library, Amazon SWF. Specifically a 'workflow' scope.

I was wondering how you would do this in Spring Boot using annotations?

1

There are 1 best solutions below

1
On

Similar question was asked here: Spring JavaConfig, bean's custom scopes and annotations

You need to create new annotation:

@Qualifier
@Scope("workflow")
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface WorkflowScoped {
}

And add it to your workflow scoped bean:

@Component
@WorkflowScoped 
public class WorkflowScopedBean {