NoSuchBeanDefinitionException:找不到类型[org.springframework.security.authentication.AuthenticationManager]的限定bean用于依赖

时间:2017-11-07 06:41:46

标签: spring applicationcontext

我正在尝试手动加载applicationContext.xml,如果我没有加载applicationContext.xml,那么删除以前的自动装配以前的代码工作正常。

Error :  Request processing failed; nested exception is 
org.springframework.beans.factory.BeanCreationException: Error 
creating bean with name 'securityServiceImpl': Injection of autowired 
dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not 
autowire field: private org.springframework.security.authentication.AuthenticationManager 
com.visualpathit.account.service.SecurityServiceImpl.authenticationManager;nested exception is  org.springframework.beans.factory.NoSuchBeanDefinitionException: No 
qualifying bean of type 
[org.springframework.security.authentication.AuthenticationManager] 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)}

ApplicationContext.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:int="http://www.springframework.org/schema/integration"
xmlns:int-amqp="http://www.springframework.org/schema/integration/amqp"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-tegration.xsd
http://www.springframework.org/schema/integration/amqp 
http://www.springframework.org/schema/integration/amqp/spring-
integration-amqp.xsd
http://www.springframework.org/schema/rabbit 
http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context.xsd">

<context:annotation-config/>
<!-- Configuration for Component Scan -->
<context:component-scan base-package="com.visualpathit.account" />  
<context:property-placeholder 
location="classpath*:rabbitmq.properties"/>
<int:channel id="inputChannel"/>
<int:gateway id="orderGateway" service-
interface="com.visualpathit.account.repository.OrderGateway" default-
request-channel="inputChannel" />  
<int-amqp:channel id="processChannel"
connection-factory="connectionFactory" 
message-driven="true"
queue-name="ha.rabbit.channel" />   
<rabbit:connection-factory id="connectionFactory"  
addresses="${rabbitmq.addresses}" username="${rabbitmq.username}"    
password="${rabbitmq.password}" /> 

<int:splitter id="orderSplitter" input-channel="inputChannel" 
output-channel="processChannel" />
<int:service-activator input-channel="processChannel" 
ref="orderProcessService" method="process" />  
</beans>

控制器代码:

    @RequestMapping(value = { "/user/rabbit"} , method = RequestMethod.GET)    
public static String rabbitmqSetUp(){
orderGateway = context.getBean(OrderGateway.class);  
try {
----
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return "welcome";
}

SecurityServiceImpl

@Service
public class SecurityServiceImpl implements SecurityService {
/** authenticationManager !*/
@Autowired
private AuthenticationManager authenticationManager;
/** userDetailsService !*/
@Autowired
private UserDetailsService userDetailsService;

/** Logger creation !*/
private static final Logger logger = 
LoggerFactory.getLogger(SecurityServiceImpl.class);
@Override
public String findLoggedInUsername() {
    Object userDetails = SecurityContextHolder.getContext()
                        .getAuthentication().getDetails();
    if (userDetails instanceof UserDetails) {
        return ((UserDetails) userDetails).getUsername();
    }

    return null;
}

0 个答案:

没有答案