Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring java配置EJB代理不工作_Java_Spring_Spring Mvc_Ejb 3.0 - Fatal编程技术网

Spring java配置EJB代理不工作

Spring java配置EJB代理不工作,java,spring,spring-mvc,ejb-3.0,Java,Spring,Spring Mvc,Ejb 3.0,在使用Spring的java配置类时,让EJB bean工作起来有问题。 具体而言,我有以下几点可以发挥作用: @Configuration @ComponentScan(basePackages = "com.company.web.config") @ImportResource(value = {"classpath:spring-beans.xml"}) public class AppConfig { } @Configuration @ComponentScan(basePacka

在使用Spring的java配置类时,让EJB bean工作起来有问题。 具体而言,我有以下几点可以发挥作用:

@Configuration
@ComponentScan(basePackages = "com.company.web.config")
@ImportResource(value = {"classpath:spring-beans.xml"})
public class AppConfig {
}

@Configuration
@ComponentScan(basePackages = "com.company.web")
public class WebConfig extends WebMvcConfigurationSupport {
   // basic Spring MVC setup omitted
}
我的spring-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:jee="http://www.springframework.org/schema/jee"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">

    <jee:local-slsb id="fooService" jndi-name="java:app/model/FooServiceBean!com.company.ejb.FooService"
      business-interface="com.company.ejb.FooService" />
</beans>
现在,我尝试摆脱XML文件。根据当地标准,slsb应相当于

<bean id="fooService"
        class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean">
    <property name="jndiName" value="java:app/model/FooServiceBean!com.company.ejb.FooService"/>
    <property name="businessInterface" value="com.company.ejb.FooService"/>
</bean>

你知道为什么这样不行吗?我使用的是Spring版本4.0.2。

问题似乎与读取配置的顺序有关,可能与双重配置加载有关

具体来说,引入一个单独的配置类并在WebConfig之前导入它似乎可以做到这一点,如下所示:

@Configuration
@Import({EJBConfig.class, WebConfig.class})
public class AppConfig {
}

@Configuration
public class EJBConfig {
    @Bean
    public LocalStatelessSessionProxyFactoryBean fooService(){
        LocalStatelessSessionProxyFactoryBean factory = new LocalStatelessSessionProxyFactoryBean();
        factory.setBusinessInterface(FooService.class);
        factory.setJndiName("java:app/model/FooServiceBean!com.company.ejb.FooService");
        return factory;
    }
}

@Configuration
@ComponentScan(basePackages = "com.company.web")
public class WebConfig extends WebMvcConfigurationSupport {
   // basic Spring MVC setup omitted
}

解释
不起作用
我已经起作用了?部署失败,因为它无法实例化我的控制器。例外情况是找不到FooService的autowire候选。您使用的是哪个Spring版本?我更新了问题。我使用Spring4.0.2。
@Bean
    public LocalStatelessSessionProxyFactoryBean fooService(){
        LocalStatelessSessionProxyFactoryBean factory = new LocalStatelessSessionProxyFactoryBean();
        factory.setBusinessInterface(FooService.class);
        factory.setJndiName("java:app/model/FooServiceBean!com.company.ejb.FooService");
        return factory;
    }
@Configuration
@Import({EJBConfig.class, WebConfig.class})
public class AppConfig {
}

@Configuration
public class EJBConfig {
    @Bean
    public LocalStatelessSessionProxyFactoryBean fooService(){
        LocalStatelessSessionProxyFactoryBean factory = new LocalStatelessSessionProxyFactoryBean();
        factory.setBusinessInterface(FooService.class);
        factory.setJndiName("java:app/model/FooServiceBean!com.company.ejb.FooService");
        return factory;
    }
}

@Configuration
@ComponentScan(basePackages = "com.company.web")
public class WebConfig extends WebMvcConfigurationSupport {
   // basic Spring MVC setup omitted
}