没有名为“springSecurityFilterChain'被定义为

时间:2014-12-29 07:26:22

标签: spring hibernate security jpa

第1节:xml文件

1 - 这是我的Web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>   ***(also including *.js,*.png and etc.)***

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>

<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring-security.xml,
        /WEB-INF/applicationContext.xml
    </param-value>
</context-param>
<!-- Spring Security -->
<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>


</web-app>

2-我的applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:jpa="http://www.springframework.org/schema/data/jpa" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cache="http://www.springframework.org/schema/cache"   
xmlns:p="http://www.springframework.org/schema/p" 
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:aop="http://www.springframework.org/schema/aop" 
xmlns:tx="http://www.springframework.org/schema/tx" 
xsi:schemaLocation="http://www.springframework.org/schema/beans
                    http://www.springframework.org/schema/beans/spring-beans.xsd
                    http://www.springframework.org/schema/context
                    http://www.springframework.org/schema/context/spring-context.xsd
                    http://www.springframework.org/schema/data/jpa 
                    http://www.springframework.org/schema/data/jpa/spring-jpa.xsd 
                    http://www.springframework.org/schema/cache 
                    http://www.springframework.org/schema/cache/spring-cache.xsd                        
                    http://www.springframework.org/schema/mvc
                    http://www.springframework.org/schema/mvc/spring-mvc.xsd
                    http://www.springframework.org/schema/aop 
                    http://www.springframework.org/schema/aop/spring-aop.xsd
                    http://www.springframework.org/schema/tx 
                    http://www.springframework.org/schema/tx/spring-tx.xsd            
                    http://www.springframework.org/schema/jee
                    http://www.springframework.org/schema/jee/spring-jee.xsd">
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>WEB-INF/resources.properties</value>
        </list>
    </property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost/fanfanfind" />
    <property name="username" value="root" />
    <property name="password" value="root" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" >
    <property name="dataSource" ref="dataSource"/>

    <property name="packagesToScan">
        <list>
            <value>com.funnyfind.userandroleinfo</value>
        </list>
    </property>

    <property name="hibernateProperties">
        <value>  
            hibernate.dialect=org.hibernate.dialect.MySQLDialect
            hibernate.hbm2ddl.auto=update  
            hibernate.show_sql=true  
            hibernate.format_sql=true;  
  </value>  
    </property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>

3-这是我的security.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
    "http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/security
    http://www.springframework.org/schema/security/spring-security.xsd">
 <http realm="Application"  use-expressions="true" auto-config="true">

    <intercept-url pattern="/login"                 access="permitAll"/>
    <intercept-url pattern="/home"                  access="hasAnyRole('ROLE_USER','ROLE_ADMIN')" />
    <form-login login-page="/login" 
                login-processing-url="/j_spring_security_check"
                authentication-failure-url="/login/failure" 
                default-target-url="/home" />
    <logout logout-success-url="/logout/success" 
            invalidate-session="true"
            delete-cookies="JSESSIONID" /> 
</http>
<global-method-security secured-annotations="disabled" /> 
<beans:bean id="customUserDetailService" class="com.funnyfind.security.CustomUserDetailService" />
<authentication-manager>
    <authentication-provider user-service-ref="customUserDetailService">
          <password-encoder hash="md5" />
    </authentication-provider>
</authentication-manager> 
</beans:beans>

4-这是主要的xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/beans"  
xmlns:b="http://www.springframework.org/schema/beans" 
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
xmlns:context="http://www.springframework.org/schema/context"  
xmlns:aop="http://www.springframework.org/schema/aop"  
xmlns:tx="http://www.springframework.org/schema/tx"  
xmlns:p="http://www.springframework.org/schema/p"  
xmlns:cache="http://www.springframework.org/schema/cache"  
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:mvc="http://www.springframework.org/schema/mvc"

xsi:schemaLocation="http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans.xsd   
      http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context.xsd   
      http://www.springframework.org/schema/aop    http://www.springframework.org/schema/aop/spring-aop.xsd   
      http://www.springframework.org/schema/tx    http://www.springframework.org/schema/tx/spring-tx.xsd
      http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
      http://www.springframework.org/schema/data/jpa  http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
      http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
      http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd" >
<context:annotation-config/>
<context:component-scan base-package="com.funnyfind" /> 
<context:component-scan base-package="com.funnyfind.security" />
<context:component-scan base-package="com.funnyfind.userandroleinforepository" />
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/views/" />
    <beans:property name="suffix" value=".jsp" />
</beans:bean>
<mvc:annotation-driven />
</beans:beans>

第2节:文件结构和文件:

FunnyFind-新的(项目名称)

- SRC

--webapp

  --WEB-INFO

    -- applicationContext.xml
    -- mvc-dispatcher-servlet.xml
    -- spring-security.xml
    -- web.xml
    -- resources.properties

第3节:错误:

创建名为'customUserDetailService'的bean时出错:注入自动连接的依赖项失败

引起:org.springframework.beans.factory.BeanCreationException:无法自动装配字段:private com.funnyfind.userandroleinfoservice.UserService

引起:org.springframework.beans.factory.BeanCreationException:创建名为'userService'的bean时出错:注入自动连接的依赖项失败;

引起:org.springframework.beans.factory.BeanCreationException:无法自动装配字段:private com.funnyfind.userandroleinforepository.UserRepository

由以下原因引起:org.springframework.beans.factory.NoSuchBeanDefinitionException:找不到类型为[com.funnyfind.userandroleinforepository.UserRepository]的限定bean依赖:预期至少有1个bean符合此依赖关系的autowire候选者。依赖注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}

第4节:版本:

春天 - 3.2.8 安全 - 3.2.2 休眠 - 4.1.2 JPA - 1.5.0

我已经完成了几乎所有针对此问题的在线说明,但是,它仍然无法解决,请帮助..谢谢。

0 个答案:

没有答案