Spring Security中未定义Java Config,没有使用springSecurityFilterChain命名的bean

时间:2019-01-27 06:42:39

标签: java spring-security struts

我正在尝试使用Struts2配置Spring Security。它可以与XML配置一起使用,但是对于Java Config,它说没有名为springSecurityFilterChain的bean可用。

尽管按照指示初始化了类。

我的WEB-INF如下  `

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    <display-name>WizRad Application</display-name>
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    <resource-ref>
        <description> DB Connection
        </description>
        <res-ref-name> jdbc/MySqlDS
        </res-ref-name>
        <res-type>javax.sql.Datasource
        </res-type>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/applicationContext.xml
        </param-value>
    </context-param>

     </resource-ref>
      <listener>
        <listener-class>
            org.apache.struts2.tiles.StrutsTilesListener
        </listener-class>
    </listener>


    <context-param>
        <param-name>tilesDefinitions</param-name>
        <param-value>/WEB-INF/tiles.xml</param-value>
    </context-param>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
      org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
        </filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


    <welcome-file-list>
        <welcome-file>/WEB-INF/jsp/LoginNew.jsp</welcome-file>
    </welcome-file-list>

</web-app>

初始化器类

package com.bnt.wizrad.spring.security;

    import org.springframework.core.annotation.Order;
    import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
    @Order(1)
    public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer {

    }

,安全配置类为

package com.bnt.wizrad.spring.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
// @EnableGlobalMethodSecurity(prePostEnabled = true)

@EnableWebSecurity
@ComponentScan(basePackages = {"com.bnt.wizrad.spring.security"})



@Order(2)
public class SecurityConfig extends WebSecurityConfigurerAdapter{

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .inMemoryAuthentication()
                .withUser("user").password("password").roles("USER");
    }
    @Override
    public void configure(WebSecurity web) throws Exception {
        web
            .ignoring()
            .antMatchers("/resources/**");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // TODO Auto-generated method stub

        http.authorizeRequests()
          .anyRequest().authenticated()
          .and().httpBasic();


    }

}
  

我尝试过   @ImportResource({“ classpath:spring-security-context.xml”,   “ file:** / WEB-INF / applicationContext.xml”})//不适用于此文件   也是

请帮助 预先感谢。

0 个答案:

没有答案