我正在尝试在spring bean中使用EJB单例bean,但不知何故它无法在运行服务器时找到此ejb并收到消息:
SEVERE: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationFailureHandler' defined in class path resource [spring-security-config.xml]: Cannot resolve reference to bean 'loginAttemptService' while setting bean property 'loginAttemptService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'loginAttemptService' is defined
这是一个EJB:
public interface ILoginAttemptService {
public boolean checkout(String username);
}
这是实施:
@Slf4j
@Stateless(name = "loginAttemptService")
@Singleton
public class LoginAttemptsService implements ILoginAttemptService {
..
}
在spring框架中,这就是我定义无状态bean的方法:
<bean id="loginAttemptServiceBean"
class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean">
<property name="jndiName"
value="java:app/osloproject-ejb/loginAttemptService"/>
<property name="businessInterface"
value="com.hospitality.hp.securitycommons.api.ILoginAttemptService"/>
</bean>
<bean id="authSuccessHandler"
class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler">
<property name="redirectStrategy">
<bean class="com.hospitality.hp.securitycommons.tools.spring.CORSCompatibleTwoFactorAuthenticationRedirectStrategy">
<property name="loginAttemptService" ref="loginAttemptServiceBean"/>
</bean>
</property>
</bean>
<bean id="authenticationFailureHandler"
class="com.hospitality.hp.securitycommons.tools.spring.AuthenticationFailureCustomHandler">
<property name="useForward" value="true"/>
<property name="defaultFailureUrl" value="/login.jsp"/>
<property name="loginAttemptService" ref="loginAttemptServiceBean"/>
</bean>
有人能告诉我为什么它找不到这个EJB的JNDI名称吗?
答案 0 :(得分:0)
尝试
<jee:local-slsb id="loginAttemptServiceBean" jndi-name="java:app/osloproject-ejb/loginAttemptService"
business-interface="com.hospitality.hp.securitycommons.api.ILoginAttemptService"/>
&#34; JEE&#34;是Spring的命名空间。还检查jndi-name值是否正确