English 中文(简体)
• 如何在框架范围内打电话给MVC控制员?
原标题:How to call Spring MVC controller within Framework?

在我春天的项目中,我确实有一份联谊会的听众,由春季管理:

<bean id="jmsFactory" class="org.apache.activemq.ActiveMQConnectionFactory" p:brokerURL="tcp://localhost:61616"/>

<bean id="simpleExampleListener" class="my.package.ExampleListener" />

<jms:listener-container container-type="default" connection-factory="jmsFactory" acknowledge="auto" concurrency="1-3">
    <jms:listener destination="TEST.FOO" ref="simpleExampleListener" method="onMessage"/>
</jms:listener-container>

在一个具体的信息中,我需要打电话给请求范围很广的春季多国公司控制员(实际上目的是叫作一项服务,这也是要求范围要求和由主计长要求的服务)。 因此,我无法直接从听众那里这样做,因为春天正在根据需要管理他们,而且他们没有申请范围约束(因为我无法通过<条码>@Autowire或<条码>进入主计长)。 解决办法之一可以是吉大港定居地,由我的控制人绘制,向卢爱尔倾斜。 但是,我认为,其类型的间接费用,或许还有某种其他方法可以避免吉大港定居地保姆协议的间接费用,并在普世贸委会框架内向主计长发出呼吁?

最佳回答

你们需要问,为什么服务类别被定义为要求范围——理想的情况是,服务层不应有任何暗示/明显依赖网络。 如果无法控制,你可以围绕以下工作开展工作: 你们需要把春季测试作为依赖物。

    class Listener {

    @Autowired
    RequestScopedService requestScopedService;


    void handle() {
        MockHttpServletRequest request = new MockHttpServletRequest();
        RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
        try {
             requestScopedService.callSomeMethod();
        } finally {
             ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).requestCompleted();
             RequestContextHolder.resetRequestAttributes();
        }

如果电灯与<代码><aop:copd-proxy/> 标签相组合,该电灯可以自动连接。 否则,你需要获得申请背景(通过执行申请目录Aware)并做调查。

问题回答

暂无回答




相关问题
array dependency injection in spring?

is there a way to use dependency injection to inject all available implementations of a specific interface in spring? This is kind of the same thing as asked here for .NET. Though my aim is to use @...

Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Grails Packaging and Naming Conventions

Packaging Controllers, Services,etc. i.e. - com.company.controllers - com.company.services Is this a good practice or should be avoided by all means?? Another worth mentioning problem I encountered ...

How can I determine Objects in application context?

I am trying to write a portlet for Liferay (using Tomcat and Spring) and need to use a database via Persistence API/Hibernate. I am using some configuration XMLs (applicationContext.xml, etc.) and ...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

热门标签