问:
Error creating bean with name 'org.springframework.security.filterChains Cannot resolve reference to bean while setting bean property 'sourceList'
I just started to learn Spring Security and have some trouble. I want to configure User login on page with password and username which stored in database. I use Hibernate and spring 4.3 along with MySQL to store data.i was trying to login using DAO Authentication using spring but i'm struck here. please help me out..

security-context.xml

```<code><!-- custom login Authentication/form -->
        <http use-expressions="true" auto-config="true" >
            <intercept-url pattern="/index*" access="hasRole('ROLE_STUDENT')"/>
            <intercept-url pattern="/resources/**" access="permitAll" />

            <form-login login-page="/login"
                        username-parameter="email"
                        password-parameter="password"
                        default-target-url="/default"
                        authentication-failure-url="/loginfailed"/>
            <logout logout-success-url="/index"/>
            <csrf/>
        </http>

        <b:bean id="daoAuthenticationprovider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider" >
            <b:property name="userDetailService" ref="userDetailService"></b:property>
        </b:bean>
        <b:bean id="authenticationmanager" class="org.springframework.security.authentication.ProviderManager">
            <b:property name="providers">
                <b:list>
                    <b:ref bean="daoAuthenticationprovider"/>
                </b:list>
            </b:property>
        </b:bean>

        <authentication-manager>
            <authentication-provider user-service-ref="userDetailService">
                <!-- <password-encoder hash="md5"></password-encoder> -->
            </authentication-provider>
        </authentication-manager>
</code>```

Spring-servlet

```<code><context:annotation-config />
    <context:component-scan base-package="com.internbridge" />

    <!-- to prevent browser back button on displaying secure resource after logout -->
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="cacheSeconds" value="0"></property>
    </bean>

    <bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
        p:location="/WEB-INF/jdbc.properties" />

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close" p:driverClassName="${jdbc.driverClassName}"
        p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}" />
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation">
            <value>classpath:hibernate.cfg.xml</value>
        </property>
        <property name="configurationClass">
            <value>org.hibernate.cfg.AnnotationConfiguration</value>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${jdbc.dialect}</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
            </props>
        </property>
    </bean>
    <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
    </bean>
    <tx:annotation-driven />
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
<!-- Spring Internationalizations -->
    <bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:messages/messages" />
        <property name="defaultEncoding" value="UTF-8" />
    </bean>

    <bean id="localeResolver"
        class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
        <property name="defaultLocale" value="tl" />
    </bean>

    <bean id="localeChangeInterceptor"
        class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <property name="paramName" value="language" />
    </bean>

    <bean id="handlerMapping"
        class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
        <property name="interceptors">
            <ref bean="localeChangeInterceptor" />
        </property>
    </bean>

    <mvc:resources mapping="/resources/**" location="/resources/" />
    <mvc:annotation-driven />
</code>```

web.xml

```<code><display-name>InternBridge</display-name>

    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>classpath:log4j.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>
    <!-- Spring initialization -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/security-context.xml,
            /WEB-INF/spring-servlet.xml
        </param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Spring security configuration -->
    <!-- filter to use spring security, be sure to use suggested name "springSecurityFilterchain"-->
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!-- Spring MVC or Servlet Mapping -->
    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>
</code>```

userdetailserviceImpl

```<code>@Service("userDetailsService")
public class userdetailserviceImpl implements UserDetailsService {
    @Autowired
    private usersDao userdao;
    @Transactional(readOnly=true)
    public UserDetails loadUserByUsername(String username)
            throws UsernameNotFoundException {
        users u=userdao.finduserbyname(username);
        if(u!=null){
            String password=u.getPassword();
            //Additional info on security object
            boolean enabled=u.getStatus().equals(userstatus.ACTIVE);
            boolean accnonexperied=u.getStatus().equals(userstatus.ACTIVE);
            boolean credentianlnonexperied=u.getStatus().equals(userstatus.ACTIVE);
            boolean accnonlocker=u.getStatus().equals(userstatus.ACTIVE);

            //lets populate user roles
            Collection<GrantedAuthority> authorities=new ArrayList<GrantedAuthority>();
            for(roles role:u.getRoless()){
                authorities.add(new SimpleGrantedAuthority(role.getRolename()));
            }

            //now lets create spring security user obj
            org.springframework.security.core.userdetails.User securityuser=new org.springframework.security.core.userdetails.User(username,password,enabled,accnonexperied,credentianlnonexperied,accnonlocker, authorities);

            return securityuser;
        }else{
            throw new UsernameNotFoundException("user not found!!!");
        }
    }

}
</code>```

dependencies

```<code><properties>
    <org.springframework.version>4.3.12.RELEASE</org.springframework.version>
  </properties>

 <dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <!-- Spring Security  -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>4.2.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>4.2.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>4.2.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-taglibs</artifactId>
        <version>4.2.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-taglibs</artifactId>
        <version>4.2.3.RELEASE</version>
    </dependency>

    <!-- Hibernate resources -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.6.7.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.3.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-commons-annotations</artifactId>
        <version>3.3.0.ga</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-annotations</artifactId>
        <version>3.3.1.GA</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.3.2.GA</version>
    </dependency>
    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>1.1.2</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.1.2</version>
    </dependency>
    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <version>20030825.184428</version>
    </dependency>
    <dependency>
        <groupId>commons-pool</groupId>
        <artifactId>commons-pool</artifactId>
        <version>20030825.183949</version>
    </dependency>
    <!-- MySQL -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.6</version>
    </dependency>
    <!-- Log4j -->
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
        <type>jar</type>
        <!-- <scope>compile</scope> -->
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>4.3.12.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.security.oauth</groupId>
        <artifactId>spring-security-oauth2</artifactId>
        <version>2.2.0.RELEASE</version>
    </dependency>

</dependencies>
</code>```

console

```<code>ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains': Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#0' while setting bean property 'sourceList' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#0': Cannot resolve reference to bean 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0' while setting constructor argument with key [5]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0': Cannot resolve reference to bean 'org.springframework.security.authentication.ProviderManager#0' while setting bean property 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': Cannot resolve reference to bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authenticationManager': Cannot resolve reference to bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' while setting constructor argument with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Cannot resolve reference to bean 'userDetailService' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'userDetailService' available
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:382)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:157)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1531)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    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.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:742)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4643)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5105)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1425)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1415)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:941)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:839)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1425)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1415)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:941)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:258)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:770)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:671)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:355)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:495)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#0': Cannot resolve reference to bean 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0' while setting constructor argument with key [5]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0': Cannot resolve reference to bean 'org.springframework.security.authentication.ProviderManager#0' while setting bean property 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': Cannot resolve reference to bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authenticationManager': Cannot resolve reference to bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' while setting constructor argument with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Cannot resolve reference to bean 'userDetailService' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'userDetailService' available
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:382)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:157)
    at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:634)
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:145)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    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.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
    ... 47 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0': Cannot resolve reference to bean 'org.springframework.security.authentication.ProviderManager#0' while setting bean property 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': Cannot resolve reference to bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authenticationManager': Cannot resolve reference to bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' while setting constructor argument with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Cannot resolve reference to bean 'userDetailService' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'userDetailService' available
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1531)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    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.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
    ... 61 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': Cannot resolve reference to bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authenticationManager': Cannot resolve reference to bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' while setting constructor argument with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Cannot resolve reference to bean 'userDetailService' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'userDetailService' available
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
    at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:634)
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:145)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    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
</code>```

答:
You have not followed proper naming conventions.

You are referring been by "userDetailService" in your configuration but the name that you have provided in your definition is "UserDetailsService"

Ideally you should have in your UserServiceDetailImpl.

@Service("userDetailService")
public class UserDetailServiceImpl implements UserDetailService {

Make changes accordingly in your java file names and you should be fine.

Body:
I just started to learn Spring Security and have some trouble. I want to configure User login on page with password and username which stored in database. I use Hibernate and spring 4.3 along with MySQL to store data.i was trying to login using DAO Authentication using spring but i'm struck here. please help me out..

security-context.xml

        <http use-expressions="true" auto-config="true" >
            <intercept-url pattern="/index*" access="hasRole('ROLE_STUDENT')"/>
            <intercept-url pattern="/resources/**" access="permitAll" />

            <form-login login-page="/login"
                        username-parameter="email"
                        password-parameter="password"
                        default-target-url="/default"
                        authentication-failure-url="/loginfailed"/>
            <logout logout-success-url="/index"/>
            <csrf/>
        </http>

        <authentication-manager>
            <authentication-provider user-service-ref="userDetailService">

            </authentication-provider>
        </authentication-manager>

Spring-servlet

<context:annotation-config />
    <context:component-scan base-package="com.internbridge" />

    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="cacheSeconds" value="0"></property>
    </bean>

    <bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
        p:location="/WEB-INF/jdbc.properties" />

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close" p:driverClassName="${jdbc.driverClassName}"
        p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}" />
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation">
            <value>classpath:hibernate.cfg.xml</value>
        </property>
        <property name="configurationClass">
            <value>org.hibernate.cfg.AnnotationConfiguration</value>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${jdbc.dialect}</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
            </props>
        </property>
    </bean>
    <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
    </bean>
    <tx:annotation-driven />
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:messages/messages" />
        <property name="defaultEncoding" value="UTF-8" />
    </bean>

    <bean id="localeResolver"
        class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
        <property name="defaultLocale" value="tl" />
    </bean>

    <bean id="localeChangeInterceptor"
        class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <property name="paramName" value="language" />
    </bean>

    <bean id="handlerMapping"
        class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
        <property name="interceptors">
            <ref bean="localeChangeInterceptor" />
        </property>
    </bean>

    <mvc:resources mapping="/resources/**" location="/resources/" />
    <mvc:annotation-driven />

web.xml

<display-name>InternBridge</display-name>

    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>classpath:log4j.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/security-context.xml,
            /WEB-INF/spring-servlet.xml
        </param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

userdetailserviceImpl

@Service("userDetailsService")
public class userdetailserviceImpl implements UserDetailsService {
    @Autowired
    private usersDao userdao;
    @Transactional(readOnly=true)
    public UserDetails loadUserByUsername(String username)
            throws UsernameNotFoundException {
        users u=userdao.finduserbyname(username);
        if(u!=null){
            String password=u.getPassword();
            //Additional info on security object
            boolean enabled=u.getStatus().equals(userstatus.ACTIVE);
            boolean accnonexperied=u.getStatus().equals(userstatus.ACTIVE);
            boolean credentianlnonexperied=u.getStatus().equals(userstatus.ACTIVE);
            boolean accnonlocker=u.getStatus().equals(userstatus.ACTIVE);

            //lets populate user roles
            Collection<GrantedAuthority> authorities=new ArrayList<GrantedAuthority>();
            for(roles role:u.getRoless()){
                authorities.add(new SimpleGrantedAuthority(role.getRolename()));
            }

            //now lets create spring security user obj
            org.springframework.security.core.userdetails.User securityuser=new org.springframework.security.core.userdetails.User(username,password,enabled,accnonexperied,credentianlnonexperied,accnonlocker, authorities);

            return securityuser;
        }else{
            throw new UsernameNotFoundException("user not found!!!");
        }
    }

}

dependencies

<properties>
    <org.springframework.version>4.3.12.RELEASE</org.springframework.version>
  </properties>

 <dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>4.2.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>4.2.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>4.2.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-taglibs</artifactId>
        <version>4.2.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-taglibs</artifactId>
        <version>4.2.3.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.6.7.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.3.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-commons-annotations</artifactId>
        <version>3.3.0.ga</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-annotations</artifactId>
        <version>3.3.1.GA</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.3.2.GA</version>
    </dependency>
    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>1.1.2</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.1.2</version>
    </dependency>
    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <version>20030825.184428</version>
    </dependency>
    <dependency>
        <groupId>commons-pool</groupId>
        <artifactId>commons-pool</artifactId>
        <version>20030825.183949</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.6</version>
    </dependency>

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
        <type>jar</type>

    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>4.3.12.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.security.oauth</groupId>
        <artifactId>spring-security-oauth2</artifactId>
        <version>2.2.0.RELEASE</version>
    </dependency>

</dependencies>

console

ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains': Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#0' while setting bean property 'sourceList' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#0': Cannot resolve reference to bean 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0' while setting constructor argument with key [5]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0': Cannot resolve reference to bean 'org.springframework.security.authentication.ProviderManager#0' while setting bean property 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': Cannot resolve reference to bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authenticationManager': Cannot resolve reference to bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' while setting constructor argument with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Cannot resolve reference to bean 'userDetailService' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'userDetailService' available
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:382)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:157)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1531)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    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.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:742)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4643)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5105)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1425)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1415)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:941)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:839)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1425)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1415)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:941)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:258)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:770)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:671)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:355)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:495)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#0': Cannot resolve reference to bean 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0' while setting constructor argument with key [5]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0': Cannot resolve reference to bean 'org.springframework.security.authentication.ProviderManager#0' while setting bean property 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': Cannot resolve reference to bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authenticationManager': Cannot resolve reference to bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' while setting constructor argument with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Cannot resolve reference to bean 'userDetailService' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'userDetailService' available
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:382)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:157)
    at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:634)
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:145)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    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.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
    ... 47 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0': Cannot resolve reference to bean 'org.springframework.security.authentication.ProviderManager#0' while setting bean property 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': Cannot resolve reference to bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authenticationManager': Cannot resolve reference to bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' while setting constructor argument with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Cannot resolve reference to bean 'userDetailService' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'userDetailService' available
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1531)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    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.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
    ... 61 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': Cannot resolve reference to bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authenticationManager': Cannot resolve reference to bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' while setting constructor argument with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Cannot resolve reference to bean 'userDetailService' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'userDetailService' available
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
    at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:634)
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:145)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    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


来源: stackexchange

问:
Using Angular 4 : How i can manage admin and web section within single project
I want to create a admin and web section in angular and i am little bit confuse that should i create two separate projects for Admin and Web respectively.
Or i can manage both in single angular 4 Application.</p>

答:
I have several projects that contains exactly what you ask. A web project that is split into 2 (sometimes 3) different "sections" depending on the role of the user that logs in. So the roles given to the user when loggin in, defines the sections (components) exposed to the user.

According to my experience and in my situation, it is best to keep the sections in the same project, because all refactoring, optimizing etc. is done in the same project, and if a section is needed to be shared, then this is very easy because its the same project.

To manage the different sections correctly then, I have spent some time creating a solid authentication system for managing roles etc., and a solid routing system that controls the sections (You can use Angular's canActivate Guard to control what is accessible).

I must also point out, that all client sided code can never be 100% secure, you must always have server-side validation for sensitive data.

ContentLicense: CC BY-SA 3.0


问:
How can I re-initialize my component in Angular 2+ when I navigate to the same url that is open without any changes in route or query parameter?
I have a left navigation pane where I have a 'Add Item' link which takes me to a form for adding an item.

My route looks like this :

{ path: 'additem', component: AddItemComponent, canActivate: [AuthGuard], data: {title: 'Add Item'} }

After the user successfully saves the item, I want to stay on the same page with the save button disabled. However when the user again clicks on the Add Item link in the left nav,I want my component to be re-initialized. How do I do this since the ngOnInit method is not invoked if the current view is the one navigated to ? I cannot subscribe to changes in query or route parameters since I have no query or route parameters.

答:
If you are using formbuilder for your form,

In your html use disabled attribute to disable the button

```<code><form [formGroup]="offerForm" (ngSubmit)="addMyOffer(offerForm.value)">
  <input type="text" formControlName="myOffer">
  <button type="submit" [disabled]="!offerForm.valid">
     <span>Add</span>
  </button>
</form>
</code>```

In your component, after saving the data, reset the form to add new offers

```<code>import { FormBuilder, FormGroup, Validators,FormControl } from '@angular/forms';

export class formComponent{
  private offerForm:FormGroup;

  constructor(private formBuilder: FormBuilder){
    this.offerForm = this.formBuilder.group({
       'myOffer' :['',Validators.required],
    });
  }

  private addMyOffer(obj:any){

     //code for saving data
     this.offerForm.reset(); // resets the form to add new offer

  }
}
</code>```

ContentLicense: CC BY-SA 4.0

Body:
If you are using formbuilder for your form,

In your html use disabled attribute to disable the button

<form [formGroup]="offerForm" (ngSubmit)="addMyOffer(offerForm.value)">
  <input type="text" formControlName="myOffer">
  <button type="submit" [disabled]="!offerForm.valid">
     <span>Add</span>
  </button>
</form>

In your component, after saving the data, reset the form to add new offers

import { FormBuilder, FormGroup, Validators,FormControl } from '@angular/forms';

export class formComponent{
  private offerForm:FormGroup;

  constructor(private formBuilder: FormBuilder){
    this.offerForm = this.formBuilder.group({
       'myOffer' :['',Validators.required],
    });
  }

  private addMyOffer(obj:any){

     //code for saving data
     this.offerForm.reset(); // resets the form to add new offer

  }
}


问:
Font-face with text shadow giving poor result
I've used font-face with text shadow which looks good both in FF 3.6 and IE 8 in windows7. In windows XP, however, it looks ok in IE but the text is not clear in Firefox 3.6. It loads and its clear for a moment but it feels that when shadow is applied it makes the font result poor. Any ideas?</p>

答:
Try these lines of code

```<code>html
{
    text-rendering: optimizeLegibility;
    font-smoothing: antialiased;
    -webkit-font-smoothing: antialiased;
}
</code>```

READ >> CSS Text-Rendering

ContentLicense: CC BY-SA 2.5

Body:
Try these lines of code

html
{
    text-rendering: optimizeLegibility;
    font-smoothing: antialiased;
    -webkit-font-smoothing: antialiased;
}

READ >> CSS Text-Rendering


问:
BufferedReader not reading entire JSON from HttpsURLConnection
I'm trying to read a JSON text from a website; I have the URL, and it's connecting fine. My current code is:

```<code>BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));

                String input;

                while ((input = br.readLine()) != null){
                    JSONObject j = new JSONObject(input);

                    Log.d(TAG,j.toString(4));
                }

                br.close();
</code>```

It's not able to read the JSON from the entire HttpsURLConnection, however. Doing a log for Android I see that it's cutting off halfway through. I think it might have something to do with the size of either input or BufferedReader, but I'm not sure how to proceed.

EDIT: This is the log

Still not getting it after the first suggestion.

```<code>05-14 17:37:29.070 3707-3755/asundar.sharks D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true

                                                          [ 05-14 17:37:29.070  3707: 3707 D/         ]
                                                          HostConnection::get() New Host Connection established 0x7f0411c26ec0, tid 3707

                                                          [ 05-14 17:37:29.120  3707: 3755 D/         ]
                                                          HostConnection::get() New Host Connection established 0x7f040937e280, tid 3755
</code>```

05-14 17:37:29.140 3707-3755/asundar.sharks I/OpenGLRenderer: Initialized EGL, version 1.4
05-14 17:37:29.210 3707-3707/asundar.sharks E/RecyclerView: No adapter attached; skipping layout
05-14 17:37:29.240 3707-3707/asundar.sharks E/RecyclerView: No adapter attached; skipping layout

答:
As JSONParser will throw error at runtime as parser.parse "End of File exception" for JSON pretty  print issue.

You can try below logic.

```<code>        String output;
        JSONObject jsonObject = null;
        StringBuilder stBuild = new StringBuilder();
        JSONParser parser = new JSONParser();
        LOGGER.debug("conn: {}", conn);
        // fetching NC response in form of buffer reader.
        BufferedReader br = new BufferedReader(new
        InputStreamReader((conn.getInputStream())));
        // reading line using bufferReader
        while ((output = br.readLine()) != null) {
            // parsing string into object.
            stBuild.append(output);
            Object obj = parser.parse(stBuild.toString());
            jsonObject = (JSONObject) obj;
            // casting object into JSONObject
        }
</code>```

Body:
I'm trying to read a JSON text from a website; I have the URL, and it's connecting fine. My current code is:

BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));

                String input;

                while ((input = br.readLine()) != null){
                    JSONObject j = new JSONObject(input);

                    Log.d(TAG,j.toString(4));
                }

                br.close();

It's not able to read the JSON from the entire HttpsURLConnection, however. Doing a log for Android I see that it's cutting off halfway through. I think it might have something to do with the size of either input or BufferedReader, but I'm not sure how to proceed.

EDIT: This is the log

Still not getting it after the first suggestion.

05-14 17:37:29.070 3707-3755/asundar.sharks D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true

                                                          [ 05-14 17:37:29.070  3707: 3707 D/         ]
                                                          HostConnection::get() New Host Connection established 0x7f0411c26ec0, tid 3707

                                                          [ 05-14 17:37:29.120  3707: 3755 D/         ]
                                                          HostConnection::get() New Host Connection established 0x7f040937e280, tid 3755

05-14 17:37:29.140 3707-3755/asundar.sharks I/OpenGLRenderer: Initialized EGL, version 1.4
05-14 17:37:29.210 3707-3707/asundar.sharks E/RecyclerView: No adapter attached; skipping layout
05-14 17:37:29.240 3707-3707/asundar.sharks E/RecyclerView: No adapter attached; skipping layout

Body:
As JSONParser will throw error at runtime as parser.parse "End of File exception" for JSON pretty  print issue.

You can try below logic.

        String output;
        JSONObject jsonObject = null;
        StringBuilder stBuild = new StringBuilder();
        JSONParser parser = new JSONParser();
        LOGGER.debug("conn: {}", conn);
        // fetching NC response in form of buffer reader.
        BufferedReader br = new BufferedReader(new
        InputStreamReader((conn.getInputStream())));
        // reading line using bufferReader
        while ((output = br.readLine()) != null) {
            // parsing string into object.
            stBuild.append(output);
            Object obj = parser.parse(stBuild.toString());
            jsonObject = (JSONObject) obj;
            // casting object into JSONObject
        }


问:
postgresql select statement result into a hash
I have a simple sql select statement with just 2 selected columns. I'd like to get the result into a simple hash.

```<code>results = db_conn.exec("SELECT hostname, ipv FROM clients")
</code>```

I'd like the hash to look something like this:

```<code>"computer1"=>"192.168.0.1"
"computer2"=>"192.168.0.2"
"computer3"=>"192.168.0.3"
</code>```

Any help is appreciated.

答:
I know this is for specific case only, but for instance if you are using the pg gem to run the query you will get a PG::Result object which has some utility methods for playing around with the actual data returned from the query.

Now what you can do after you've run your query

```<code>results = db_conn.exec("SELECT hostname, ipv FROM clients")
</code>```

Since you are selecting only two columns running the values method on results will return you a two dimensional array.

```<code>[
  ["computer1", "192.168.0.1"],
  ["computer2", "192.168.0.2"],
  ["computer3", "192.168.0.3"],
]
</code>```

So in that case to get the wanted result

```<code>"computer1"=>"192.168.0.1"
"computer2"=>"192.168.0.2"
"computer3"=>"192.168.0.3"
</code>```

You can reuse the ::[] method on Hash. So the final statement will be something like

```<code>Hash[db_conn.exec("SELECT hostname, ipv FROM clients").values]
</code>```

Body:
I have a simple sql select statement with just 2 selected columns. I'd like to get the result into a simple hash.

results = db_conn.exec("SELECT hostname, ipv FROM clients")

I'd like the hash to look something like this:

"computer1"=>"192.168.0.1"
"computer2"=>"192.168.0.2"
"computer3"=>"192.168.0.3"

Any help is appreciated.

Body:
I know this is for specific case only, but for instance if you are using the pg gem to run the query you will get a PG::Result object which has some utility methods for playing around with the actual data returned from the query.

Now what you can do after you've run your query

results = db_conn.exec("SELECT hostname, ipv FROM clients")

Since you are selecting only two columns running the values method on results will return you a two dimensional array.

[
  ["computer1", "192.168.0.1"],
  ["computer2", "192.168.0.2"],
  ["computer3", "192.168.0.3"],
]

So in that case to get the wanted result

"computer1"=>"192.168.0.1"
"computer2"=>"192.168.0.2"
"computer3"=>"192.168.0.3"

You can reuse the ::[] method on Hash. So the final statement will be something like

Hash[db_conn.exec("SELECT hostname, ipv FROM clients").values]


问:
How do you check whether the given IP is internal or not
How do you check whether a given IP is internal or not using only javascript?

For example if you are given an IP of 192.168.1.1 the script should validate this and alert if this is an internal or external IP.

答:
You could use ipaddr.js library and check whether it returns "private":

```<code>const ipaddrJs = require('ipaddr.js');
ipaddrJs.parse('192.168.5.1').range()
> 'private'
</code>```

https://github.com/whitequark/ipaddr.js/blob/master/lib/ipaddr.js

And if you use Node.js, take a look here: https://www.npmjs.com/package/ipaddr.js

Body:
You could use ipaddr.js library and check whether it returns "private":

const ipaddrJs = require('ipaddr.js');
ipaddrJs.parse('192.168.5.1').range()
> 'private'

https://github.com/whitequark/ipaddr.js/blob/master/lib/ipaddr.js

And if you use Node.js, take a look here: https://www.npmjs.com/package/ipaddr.js


问:
AWK: increment a field based on values from previous line
Given the following input for AWK:

```<code>10;20;20
8;41;41
15;52;52
</code>```

How could I increase/decrease the values so that:

$1 = remains unchanged

$2 = $2 of previous line + $1 of previous line + 1

$3 = $3 of previous line + $1 of previous line + 1

So the desired output would be:

```<code>10;20;20
8;31;31
15;40;40
</code>```

I need to auto-increment and loop over the lines,
using associative arrays, but it's confusing for me.
Surely, this doesn't work as desired:

```<code>#!/bin/awk -f

BEGIN { FS = ";" }

{
print ln, st, of
ln=$1
st=$2 + ln + 1
of=$3 + ln + 1
}
</code>```

Body:
Given the following input for AWK:

10;20;20
8;41;41
15;52;52

How could I increase/decrease the values so that:

$1 = remains unchanged

$2 = $2 of previous line + $1 of previous line + 1

$3 = $3 of previous line + $1 of previous line + 1

So the desired output would be:

10;20;20
8;31;31
15;40;40

I need to auto-increment and loop over the lines,
using associative arrays, but it's confusing for me.
Surely, this doesn't work as desired:

#!/bin/awk -f

BEGIN { FS = ";" }

{
print ln, st, of
ln=$1
st=$2 + ln + 1
of=$3 + ln + 1
}

Body:
awk 'BEGIN{
           FS = OFS = ";"
     }
     FNR>1{
           $2 = p2 + p1 + 1
           $3 = p3 + p1 + 1
     }
     {
          p1=$1; p2=$2; p3=$3
     }1
    ' infile

Input:

$ cat infile
10;20;20
8;41;41
15;52;52

Output:

awk 'BEGIN{FS=OFS=";"}FNR>1{$2=p2+p1+1; $3=p3+p1+1 }{p1=$1; p2=$2; p3=$3}1' infile
10;20;20
8;31;31
15;40;40

Or store only fields of your interest

awk -v myfields="2,3" '
    BEGIN{
        FS=OFS=";";
        split(myfields,t,/,/)
    }
    {
        for(i in t)
        {
            if(FNR>1)
            {
                $(t[i]) = a[t[i]] + a[1] + 1
            }

            a[t[i]] = $(t[i])
        }
            a[1] = $1
    }1' infile


问:
How to download FileVersion content from Sharepoint Online using CSOM

Question

How do I read file content of the specific version?

What I have tried

I've tried:

```<code>var webClient = new WebClient() {Credentials = Context.Credentials })
webClient.DownloadString($"{Context.Url}{fileVersion.Url}");
</code>```

but the Credentials is null. I've tried also UseDefaultCredential = true, but in both cases I'm getting 403 forbidden:

System.Net.WebException: 'The remote server returned an error: (403) Forbidden.'

I've also tried:

```<code>File.OpenBinaryDirect(sharepoint.Context, fileVersion.Url)
//fileVersion.Url == "_vti_history/512/ListName/filename.xml"

> Specified argument was out of the range of valid values.
> Parameter name: serverRelativeUrl
</code>```

and also starting with /:

```<code> File.OpenBinaryDirect(sharepoint.Context, "/" + fileVersion.Url)
</code>```

System.Net.WebException: 'The remote server returned an error: (404) Not Found.'

How do I create ClientContext:

I use sharepoint PnP to create and authenticate my ClientContext:

```<code>var authentication = new OfficeDevPnP.Core.AuthenticationManager();
Context = authentication.GetWebLoginClientContext(siteUrl);
</code>```

I'm able to retrieve list of FileVersion:

```<code>var items = list.GetItems(camlQuery);
Context.Load(items);
Context.ExecuteQuery();
foreach (ListItem item in items)
{
    sharepoint.Context.Load(item.Versions);
    sharepoint.Context.Load(item.File.Versions);
    sharepoint.Context.Load(item.File);

    sharepoint.Context.ExecuteQuery();

    foreach (var fileVersion in item.File.Versions)
    {
         ReadFile(fileVersion);
    }
}
</code>```

here are versions of my libraries:

```<code><package id="Microsoft.SharePointOnline.CSOM" version="16.1.7018.1200" targetFramework="net461" />
<package id="SharePointPnP.IdentityModel.Extensions" version="1.2.2" targetFramework="net461" />
<package id="SharePointPnPCoreOnline" version="2.19.1710.2" targetFramework="net461" />
</code>```

答:
I've hacked the webclient authentication by stealing cookies from ClientContext:

```<code>var authentication = new OfficeDevPnP.Core.AuthenticationManager();
context = authentication.GetWebLoginClientContext(siteUrl);
webClient = new WebClient();
context.ExecutingWebRequest += StealCookieOnExecutingWebRequest;
void StealCookieOnExecutingWebRequest(object sender, WebRequestEventArgs e)
{
    var cookies = e.WebRequestExecutor.WebRequest.CookieContainer;
    webClient.Headers[HttpRequestHeader.Cookie] = cookies.GetCookieHeader(new Uri(SiteUrl));
    context.ExecutingWebRequest -= StealCookieOnExecutingWebRequest;
}
</code>```

I will not mark this as answer yet, since there might be better solution.

Body:
Question

How do I read file content of the specific version?

What I have tried

I've tried:

var webClient = new WebClient() {Credentials = Context.Credentials })
webClient.DownloadString($"{Context.Url}{fileVersion.Url}");

but the Credentials is null. I've tried also UseDefaultCredential = true, but in both cases I'm getting 403 forbidden:

System.Net.WebException: 'The remote server returned an error: (403) Forbidden.'

I've also tried:

File.OpenBinaryDirect(sharepoint.Context, fileVersion.Url)
//fileVersion.Url == "_vti_history/512/ListName/filename.xml"

> Specified argument was out of the range of valid values.
> Parameter name: serverRelativeUrl

and also starting with /:

 File.OpenBinaryDirect(sharepoint.Context, "/" + fileVersion.Url)

System.Net.WebException: 'The remote server returned an error: (404) Not Found.'

How do I create ClientContext:

I use sharepoint PnP to create and authenticate my ClientContext:

var authentication = new OfficeDevPnP.Core.AuthenticationManager();
Context = authentication.GetWebLoginClientContext(siteUrl);

I'm able to retrieve list of FileVersion:

var items = list.GetItems(camlQuery);
Context.Load(items);
Context.ExecuteQuery();
foreach (ListItem item in items)
{
    sharepoint.Context.Load(item.Versions);
    sharepoint.Context.Load(item.File.Versions);
    sharepoint.Context.Load(item.File);

    sharepoint.Context.ExecuteQuery();

    foreach (var fileVersion in item.File.Versions)
    {
         ReadFile(fileVersion);
    }
}

here are versions of my libraries:

<package id="Microsoft.SharePointOnline.CSOM" version="16.1.7018.1200" targetFramework="net461" />
<package id="SharePointPnP.IdentityModel.Extensions" version="1.2.2" targetFramework="net461" />
<package id="SharePointPnPCoreOnline" version="2.19.1710.2" targetFramework="net461" />

Body:
I've hacked the webclient authentication by stealing cookies from ClientContext:

var authentication = new OfficeDevPnP.Core.AuthenticationManager();
context = authentication.GetWebLoginClientContext(siteUrl);
webClient = new WebClient();
context.ExecutingWebRequest += StealCookieOnExecutingWebRequest;
void StealCookieOnExecutingWebRequest(object sender, WebRequestEventArgs e)
{
    var cookies = e.WebRequestExecutor.WebRequest.CookieContainer;
    webClient.Headers[HttpRequestHeader.Cookie] = cookies.GetCookieHeader(new Uri(SiteUrl));
    context.ExecutingWebRequest -= StealCookieOnExecutingWebRequest;
}

I will not mark this as answer yet, since there might be better solution.