Spring混合XML /注释配置

时间:2015-09-18 13:08:19

标签: java spring inversion-of-control

我们继承了一个Web应用程序。此应用程序使用可以通过命令行启动的API。 两者都是Spring架构。

不幸的是,API是注释配置,Web应用程序是混合的。

Web应用程序有一个applicationContext,它导入API的applicationContext并进行组件扫描。 然后是一个带有完整XML的servlet配置。此配置是使用旧的Spring版本(2.5)和旧控制器。

控制器定义了一个引用实现服务的属性。当然,该服务是一个注释服务(带有范围原型),它具有DAO属性(@Autowired)。 在此控制器中,实现了在接口和setter上定义的经典私有属性。

我们的问题如下:服务在Controller中正确实现,而不是DAO到服务中。

有什么想法吗?

[edit]配置文件:

的applicationContext.xml

<import resource="classpath*:/xxxApplicationContext.xml"/>
<context:annotation-config/>
<context:component-scan base-package="xxx.xxx.api"/>
...

xxxApplicationContext

<aop:aspectj-autoproxy proxy-target-class="true"/>
...

XXX-servlet.xml中

<bean id="theController" class="xxx.xxx.controller.XxxController">
    <property name="sessionForm">
        <value>false</value>
    </property>
    ...
    <property name="xxxService" ref="xxxServiceImpl"/>
</bean>

XxxController

public class XxxController extends SimpleFormController implements Validator {

    private xxxService xxxService;

    public void setXxxService(XxxService xxxService) {
        this.xxxService = xxxService;
    }
}

xxxServiceImpl

@Service
@Scope("prototype")
public class XxxServiceImpl implements XxxService {
    @Autowired
    private XxxDao xxxDao;
...
}

0 个答案:

没有答案