有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Java配置SpringSecurity中未定义使用springSecurityFilterChain命名的bean

我正在尝试使用Struts2配置Spring安全性。它使用XML配置,但使用Java配置时,它表示没有名为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();


    }

}

I tried it with @ImportResource({"classpath:spring-security-context.xml", "file:**/WEB-INF/applicationContext.xml"}) // Did Not work with this too

请帮忙 提前谢谢


共 (0) 个答案