Spring java配置EJB代理不工作
在使用Spring的java配置类时,让EJB bean工作起来有问题。 具体而言,我有以下几点可以发挥作用: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
@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
}