Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java spring引导用户和会话mongo_Java_Spring_Mongodb_Spring Mvc_Session - Fatal编程技术网

Java spring引导用户和会话mongo

Java spring引导用户和会话mongo,java,spring,mongodb,spring-mvc,session,Java,Spring,Mongodb,Spring Mvc,Session,我正在尝试将spring boot配置为对商店用户和会话使用mongoDB。我可以存储用户和会话,但在不同的项目中,当我将它们放在同一个项目中时,SessionRepositoryFilter的自动连接失败 下面是错误: 27/01/17 09:08:32 INFO [web.context.ContextLoader] Root WebApplicationContext: initialization completed in 8576 ms 27/01/17 09:08:33 ERROR

我正在尝试将spring boot配置为对商店用户和会话使用mongoDB。我可以存储用户和会话,但在不同的项目中,当我将它们放在同一个项目中时,SessionRepositoryFilter的自动连接失败

下面是错误:

27/01/17 09:08:32 INFO  [web.context.ContextLoader] Root WebApplicationContext: initialization completed in 8576 ms
27/01/17 09:08:33 ERROR [embedded.tomcat.TomcatStarter] Error starting Tomcat context: org.springframework.beans.factory.BeanCreationException
27/01/17 09:08:33 WARN  [context.embedded.AnnotationConfigEmbeddedWebApplicationContext] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
27/01/17 09:08:33 ERROR [springframework.boot.SpringApplication] Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)
    at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)
    at es.indra.itec.sis.srv.SisServerRunner.main(SisServerRunner.java:53)
Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:99)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:76)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:457)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:168)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:160)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130)
    ... 8 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityConfiguration.WebSecurityConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.session.web.http.SessionRepositoryFilter es.indra.itec.sis.security.config.SecurityConfiguration$WebSecurityConfiguration.sessionSessionRepositoryFilter; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sessionRepositoryFilter': Requested bean is currently in creation: Is there an unresolvable circular reference?
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:368)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springframework.boot.context.embedded.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:233)
    at org.springframework.boot.context.embedded.ServletContextInitializerBeans.addAsRegistrationBean(ServletContextInitializerBeans.java:181)
    at org.springframework.boot.context.embedded.ServletContextInitializerBeans.addAsRegistrationBean(ServletContextInitializerBeans.java:176)
    at org.springframework.boot.context.embedded.ServletContextInitializerBeans.addAdaptableBeans(ServletContextInitializerBeans.java:158)
    at org.springframework.boot.context.embedded.ServletContextInitializerBeans.<init>(ServletContextInitializerBeans.java:79)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getServletContextInitializerBeans(EmbeddedWebApplicationContext.java:237)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.selfInitialize(EmbeddedWebApplicationContext.java:224)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.access$000(EmbeddedWebApplicationContext.java:85)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext$1.onStartup(EmbeddedWebApplicationContext.java:209)
    at org.springframework.boot.context.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:55)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5244)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.session.web.http.SessionRepositoryFilter es.indra.itec.sis.security.config.SecurityConfiguration$WebSecurityConfiguration.sessionSessionRepositoryFilter; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sessionRepositoryFilter': Requested bean is currently in creation: Is there an unresolvable circular reference?
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
    ... 34 more
Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sessionRepositoryFilter': Requested bean is currently in creation: Is there an unresolvable circular reference?
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.beforeSingletonCreation(DefaultSingletonBeanRegistry.java:347)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1199)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
    ... 36 more
27/01/17 09:08:32信息[web.context.ContextLoader]根WebApplicationContext:初始化在8576毫秒内完成
27/01/17 09:08:33错误[embedded.tomcat.TomcatStarter]启动tomcat上下文时出错:org.springframework.beans.factory.BeanCreationException
27/01/17 09:08:33警告[context.embedded.AnnotationConfigEmbeddedWebApplicationContext]上下文初始化期间遇到异常-取消刷新尝试:org.springframework.context.ApplicationContextException:无法启动嵌入式容器;嵌套异常为org.springframework.boot.context.embedded.EmbeddedServletContainerException:无法启动嵌入式Tomcat
27/01/17 09:08:33错误[springframework.boot.SpringApplication]应用程序启动失败
org.springframework.context.ApplicationContextException:无法启动嵌入式容器;嵌套异常为org.springframework.boot.context.embedded.EmbeddedServletContainerException:无法启动嵌入式Tomcat
位于org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133)
位于org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
位于org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
位于org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)
位于org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)
位于org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
位于org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)
位于org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)
位于es.indra.itec.sis.srv.SisServerRunner.main(SisServerRunner.java:53)
原因:org.springframework.boot.context.embedded.EmbeddedServletContainerException:无法启动嵌入式Tomcat
位于org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:99)
位于org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.(TomcatEmbeddedServletContainer.java:76)
位于org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.gettomcatembeddedservletContainerContainer(TomcatEmbeddedServletContainerFactory.java:457)
位于org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.GetEmbeddedServletContainerFactory(TomcatEmbeddedServletContainerFactory.java:168)
位于org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:160)
位于org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130)
... 8个以上
原因:org.springframework.beans.factory.BeanCreationException:创建名为“securityConfiguration.WebSecurityConfiguration”的bean时出错:自动连线依赖项的注入失败;嵌套异常为org.springframework.beans.factory.beancreatitionException:无法自动连接字段:private org.springframework.session.web.http.SessionRepositoryFilter es.indra.itec.sis.security.config.SecurityConfiguration$WebSecurityConfiguration.SessionRepositoryFilter;嵌套异常为org.springframework.beans.factory.beanCurrentlyIncrementationException:创建名为“sessionRepositoryFilter”的bean时出错:请求的bean当前正在创建中:是否存在无法解析的循环引用?
位于org.springframework.beans.factory.annotation.AutoWiredNotationBeanPostProcessor.postProcessPropertyValues(AutoWiredNotationBeanPostProcessor.java:334)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
位于org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
位于org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
位于org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
位于org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
位于org.springframework.beans.factory.support.ConstructorResolver.InstanceUsingFactoryMethod(ConstructorResolver.java:368)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.InstanceUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
位于org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
位于org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
位于org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
在org.sp
@Configuration
public class SecurityConfiguration {

    /**
     * Web Security for managing authentication.
     */
    @Configuration
    @EnableWebMvcSecurity
    protected static class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {

        /**
         * User Service for authentication.
         */
        @Autowired
        private CustomUserDetailsService customUserService;

        @Autowired
        private SessionRepositoryFilter<ExpiringSession> sessionSessionRepositoryFilter;

        @Bean
        public HttpSessionStrategy httpSessionStrategy() {
            return new CookieHttpSessionStrategy();
        }

        @Bean
        public SessionRepositoryFilter<ExpiringSession> sessionRepositoryFilter(
                SessionRepository<ExpiringSession> sessionRepository,
                HttpSessionStrategy httpSessionStrategy
        ) {
            SessionRepositoryFilter<ExpiringSession> sessionRepositoryFilter = new SessionRepositoryFilter<>(sessionRepository);
            sessionRepositoryFilter.setHttpSessionStrategy(httpSessionStrategy);
            this.sessionSessionRepositoryFilter = sessionRepositoryFilter;
            return sessionRepositoryFilter;
        }

        @Bean
        public SessionRepository<ExpiringSession> sessionRepository() {
            return new MongoSessionRepository(10);
        }

        @Override
        @Bean
        public AuthenticationManager authenticationManagerBean() throws Exception {
            return super.authenticationManagerBean();
        }

        @Override
        protected final void configure(final AuthenticationManagerBuilder auth) throws Exception {
            auth.userDetailsService(customUserService).passwordEncoder(SecurityConstants.PASSWORD_ENCODER);
        }

        @Override
        public void configure(WebSecurity webSecurity) throws Exception {
            // ExtJS For common server deployment
            webSecurity.ignoring().antMatchers("/");
            webSecurity.ignoring().antMatchers("/index.html");
            webSecurity.ignoring().antMatchers("/cache.appcache");
            webSecurity.ignoring().antMatchers("/classic.json*");
            webSecurity.ignoring().antMatchers("/resources/**");
            webSecurity.ignoring().antMatchers("/classic/**");
            webSecurity.ignoring().antMatchers("/sisfiles/**");

            // Websocket security
            webSecurity.ignoring().antMatchers("/message");
        }

        @Override
        public final void configure(final HttpSecurity http) throws Exception {
            // CSRF disabled because we only use our own services (necesary for
            // third parties)
            http.csrf().disable();

            http
            .logout().permitAll().and()
            .formLogin().permitAll().and()
            .addFilterBefore(this.sessionSessionRepositoryFilter, ChannelProcessingFilter.class);
            // Anyone can request for a security token
            http.authorizeRequests().antMatchers("/oauth/token").anonymous();

            //http.authorizeRequests().anyRequest().fullyAuthenticated();

        }

    }
        /**
         * Oauth2 Configuration.
         */
        @Configuration
        @EnableAuthorizationServer
        protected static class OAuth2Config extends AuthorizationServerConfigurerAdapter {

            /**
             * Authentication Provider.
             */
            @Autowired
            @Qualifier("authenticationManagerBean")
            private AuthenticationManager authenticationManager;

            /**
             * User Service for authentication.
             */
            @Autowired
            private CustomUserDetailsService customUserService;

            /**
             * We need to override the Spring Security service for users,
             * because we want to use our own custom user service (connected to
             * BBDD).
             *
             * @return UserDetailsService Returns an instance of our custom
             *         service
             */
            @Bean
            public UserDetailsService userDetailsService() {
                return customUserService;
            }

            /**
             * Client Service for authentication.
             */
            @Autowired
            private IClientOAuth2DetailsService customClientDetailsService;

            /**
             * We need to override the Spring Security service for clients,
             * because we want to use our own custom client service (in memory,
             * but it migth goes to BBDD).
             *
             * @return ClientDetailsService Returns an instance of our custom
             *         service
             * @throws Exception
             *             Error
             */
            @Bean
            public ClientDetailsService clientDetailsService() throws Exception {
                return customClientDetailsService;
            }

            @Override
            public final void configure(final AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
                endpoints.authenticationManager(authenticationManager);
            }

            /**
             * We need to set our custom client service for OAuth2
             * Configuration.
             */
            @Override
            public final void configure(final ClientDetailsServiceConfigurer clients) throws Exception {
                clients.withClientDetails(clientDetailsService());
            }
        }
}
    @Bean
    public SessionRepositoryFilter<ExpiringSession> sessionRepositoryFilter(
            SessionRepository<ExpiringSession> sessionRepository,
            HttpSessionStrategy httpSessionStrategy
    ) {
        SessionRepositoryFilter<ExpiringSession> sessionRepositoryFilter = new SessionRepositoryFilter<>(sessionRepository);
        sessionRepositoryFilter.setHttpSessionStrategy(httpSessionStrategy);
        this.sessionSessionRepositoryFilter = sessionRepositoryFilter; //Remove this.
        return sessionRepositoryFilter;
    }