Search code examples
javaannotationsjerseyjavabeansjava-ee-6

How to replace annotation @Dependent and @ApplicationScoped in java SE and jersey?


I use java 8 SE and jersey. I found example of jwt service here, there is used java 6 EE. Does someone know about analogs of this annotations or other solution of this problem?


Solution

  • I solved it by replacing this annotations on @Singelton and adding

    ApplicationBinder

    public class ApplicationBinder extends AbstractBinder {
        @Override
        protected void configure() {
            bind(UserService.class).to(UserService.class).in(Singleton.class);
        }
    }
    

    ResourceConfig

    public class ApplicationConfig  extends ResourceConfig {
        public ApplicationConfig() {
            register(new ApplicationBinder());
            packages(true, "api");
        }
    }
    

    than I just can inject bean-classes by annotation @Inject