Java JBoss4上带有EJB注释的BeanNotOfRequiredTypeException

Java JBoss4上带有EJB注释的BeanNotOfRequiredTypeException,java,spring,struts2,annotations,ejb,Java,Spring,Struts2,Annotations,Ejb,问题: 部署WAR文件时出现以下异常 Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'campaigner-ejb/SecurityServiceImpl/remote' must be of type [com.campaigner.service.SecurityServiceRemote], but was actually of type [com.sun.p

问题:

部署WAR文件时出现以下异常

Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'campaigner-ejb/SecurityServiceImpl/remote' must be of type [com.campaigner.service.SecurityServiceRemote], but was actually of type [com.sun.proxy.$Proxy172]
我已经在网上搜索了这么多,但还没有找到答案

背景:

我正在用Java5运行JBoss4,因为这是我的托管服务的包。 今年晚些时候,我可能会升级软件包,但这不是一个考虑现在。 在愉快地使用XDoclet多年之后,我终于开始使用注释了。 因此,我尽量不使用任何XML文件,尽管这似乎不可能。 我使用的是Spring3.2.13和Struts2.2.3.1(因为我使用的是Java5)。 我的项目由多个WAR文件和一个EJBJAR文件组成。我现在决定不使用一个EAR文件来封装它们。 我已经读到,将CGLIB jar包含到我的项目中,并将proxy target class=“true”添加到我的一个XML文件中可能会解决这个问题, 但是,我还不能确定这应该放在哪个文件中

以下是我的Java代码:

@Remote
public interface SecurityServiceRemote extends SecurityService
{
}


@TransactionManagement(value = TransactionManagementType.CONTAINER)
@TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
@Stateless
@Interceptors(SpringBeanAutowiringInterceptor.class)
public class SecurityServiceImpl extends AbstractCampaignerServiceImpl implements
    SecurityServiceLocal, SecurityServiceRemote
{
}
ServiceFactory由Struts2操作使用。请注意,这里我没有引用类;只有接口

@Component
public class ServiceFactory
{
  private SecurityServiceRemote       securityService;

  public SecurityServiceRemote getSecurityService() throws ApplicationException
  {
    return securityService;
  }

  @EJB(name = "SecurityServiceImpl", mappedName = "campaigner-ejb/SecurityServiceImpl/remote")
  public void setSecurityService(
    SecurityServiceRemote securityService)
  {
    this.securityService = securityService;
  }
}
下面是EJBJAR文件中包含的精简XML文件

beanRefContent.xml

<beans>  
  <!--
    SpringBeanAutowiringInterceptor needs this file.
    We need SpringBeanAutowiringInterceptor to autowire the EJBs. 
   -->
  <bean
    class="org.springframework.context.support.ClassPathXmlApplicationContext">
    <constructor-arg value="classpath:campaignerContext.xml" />
  </bean>
</beans>

ActivaterContext.xml

<beans>
  <context:component-scan base-package="com.campaigner.dao.jpa,com.campaigner.service.impl" />

  <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="campaigner" />
  </bean>

  <bean id="em" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
  </bean>
</beans>
<beans>
  <context:component-scan base-package="com.campaigner.service" />
</beans>

下面是我的WAR文件中包含的精简XML文件

applicationContext.xml

<beans>
  <context:component-scan base-package="com.campaigner.dao.jpa,com.campaigner.service.impl" />

  <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="campaigner" />
  </bean>

  <bean id="em" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
  </bean>
</beans>
<beans>
  <context:component-scan base-package="com.campaigner.service" />
</beans>

struts.xml

<struts>
  <constant name="struts.custom.i18n.resources" value="campaigner_messages" />
  <constant name="struts.convention.action.includeJars" value=".*?/campaigner\-web.*?jar(!/)?"/>
  <constant name="struts.convention.action.fileProtocols" value="jar,zip"/>
  <constant name="struts.convention.default.parent.package" value="convention-tiles"/>

  <package name="convention-tiles" extends="struts-default">
    <result-types>
      <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
    </result-types>
  </package>
</struts>

web.xml

<web-app>
  <display-name>campaigner</display-name>

  <context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>campaigner_messages</param-value>
  </context-param>
  <context-param>
    <param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</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>
    <init-param>
      <param-name>actionPackages</param-name>
      <param-value>com.campaigner.web.actions</param-value>
    </init-param>
    <init-param>
      <param-name>struts.devMode</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>

  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <listener>
    <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
  </listener>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <session-config>
    <session-timeout>30</session-timeout>
  </session-config>

  <welcome-file-list>
    <welcome-file>/index</welcome-file>
  </welcome-file-list>
</web-app>

竞选者
javax.servlet.jsp.jstl.fmt.localizationContext
竞选者信息
org.apache.tiles.impl.basictelescontainer.DEFINITIONS\u CONFIG
/WEB-INF/tiles.xml
支柱2
org.apache.struts2.dispatcher.ng.filter.strutspreadexecutefilter
行动包
com.campainter.web.actions
struts.devMode
真的
支柱2
/*
org.apache.struts2.tiles.StrutsTilesListener
org.springframework.web.context.ContextLoaderListener
30
/索引

。谢谢,但我没有使用上下文。相反,@EJB注释似乎正在处理该查找。此外,ServiceFactory.setSecurityService()方法已将SecurityServiceRemote用作参数。