Java Config. В Spring Security не определен bean-компонент с именем springSecurityFilterChain. - PullRequest
0 голосов
/ 27 января 2019

Я пытаюсь настроить Spring Security с Struts2. Он работает с конфигурацией XML, но в Java Config говорится, что ни один из компонентов с именем springSecurityFilterChain недоступен.

Это несмотря на инициализацию классов в соответствии с указаниями.

Мой 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 ({ "Путь к классам: весна-безопасности context.xml", "file: ** / WEB-INF / applicationContext.xml"}) // Не работал с этим тоже

Пожалуйста, помогите Заранее спасибо.

...