- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我这样写代码:
@ContextConfiguration(locations = { "classpath:/test/BeanConfig.xml" })
@RunWith(SpringJUnit4ClassRunner.class)
//@WebAppConfiguration
public class CandidateControllerTest {
@Autowired
FilterChainProxy springSecurityFilterChain;
...
}
我必须在哪里编写此代码有效的内容?
堆栈跟踪:
ERROR: org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@48834af6] to prepare test instance [controllers.CandidateControllerTest@23ae81ab]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'controllers.CandidateControllerTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.springframework.security.web.FilterChainProxy controllers.CandidateControllerTest.springSecurityFilterChain; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.security.web.FilterChainProxy] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1116)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanPr
....
我不太了解 Spring 配置。请帮忙。
更新
发布配置文件:
BeanConfig.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<!-- Включаем опцию использования конфигурационных аннотаций (@Annotation-based configuration)-->
<context:annotation-config />
<context:component-scan base-package="com.epam.hhsystem.jpa" />
<context:component-scan base-package="com.epam.hhsystem.services" />
<!-- Файл с настройками ресурсов для работы с данными (Data Access Resources) -->
<import resource="data.xml" />
</beans>
数据.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<!-- Настраивает управление транзакциями с помощью аннотации @Transactional -->
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- Менеджер транзакций -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- Непосредственно бин dataSource -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
p:url="jdbc:sqlserver://10.16.9.52:1433;databaseName=hhsystemTest;"
p:username="userNew"
p:password="Pass12345" />
<!-- Настройки фабрики сессий Хибернейта -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:test/hibernate.cfg.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.connection.charSet">UTF-8</prop>
<!-- <prop key="hibernate.hbm2ddl.auto">create-drop</prop> -->
</props>
</property>
</bean>
</beans>
运行我的应用程序需要哪些配置?
最佳答案
似乎您还没有在配置中定义那个 bean。
你可以尝试添加这个
<bean id="springSecurityFilterChain"
class="org.springframework.security.web.FilterChainProxy">
<!-- properties -->
</bean>
并检查你的项目中是否包含了spring security。
关于java - FilterChainProxy 不会 Autowiring ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19162347/
我有两个应用相同过滤器的模式。 除了上述两个之外,还有许多其他独特的模式和一个通用模式 /**/*.do*/** 我可以像下面这样在 pattern 属性中指定逗号分隔的多个模式吗: 最佳答案
我这样写代码: @ContextConfiguration(locations = { "classpath:/test/BeanConfig.xml" }) @RunWith(SpringJUnit
我试图找出一个涉及 Spring Security 和 SAML 的问题。我们正在尝试使用 Spring Security (spring-security-core-3.1.1.RELEASE.ja
我遇到与 Spring Saml2 相关的 Spring Security 配置问题,这会导致即使 IDP 成功响应,身份验证也始终为空。 我将 spring-security-saml2-core
我有一个 spring 应用程序,其配置文件如下所示。所有配置似乎都是正确的,但在调试时我发现,在初始化期间,spring 为 FilterSecurityInterceptor 创建了两个 bean
我需要测试我的 REST Controller ,它们使用 Spring Security 进行保护。我正在使用 MockMvc 作为 spring security reference sugges
我已将自己的过滤器配置为 spring security 中的 FilterChainProxy 的一部分。我很惊讶 init() 方法(从 Filter 接口(interface)实现)没有在这个过
我尝试使用 spring-security,但出现了这个错误。 java.lang.NullPointerException at org.springframework.security.web.F
我正在尝试在 Grails 应用程序中编写 LogoutController。我找到了一个工作代码: package myPackage import grails.plugin.springsecu
我正在尝试使用 spring 配置我的自定义过滤器 AccountVerificationFilter 并收到 NPE,这些是我的配置 我在 web.xml 中配置了 cpFilterCHain,如下
我是一名优秀的程序员,十分优秀!