在我们的应用程序中,我们使用JSON进行请求和响应.控制器方法使用@RequestBody()进行注释.返回的对象,例如TransferResponse.我想从@ResponseBody获取此对象.我已经设置了拦截器postHandle方法:
@Override
public void postHandle(HttpServletRequest request,
HttpServletResponse response,
Object handler,
ModelAndView modelAndView) throws java.lang.Exception
{
....
}
Run Code Online (Sandbox Code Playgroud)
那么如何在这个postHandle方法中获取JSON呢?
在此先感谢GM
我需要将消息从一个ActiveMQ实例上的队列移动到另一个ActiveMQ实例.有没有办法使用spring boot配置连接到两个不同的ActiveMQ实例?
我需要创建多个connectionFactories吗?如果是这样,那么JmsTemplate如何知道连接哪个ActiveMQ实例?
@Bean
public ConnectionFactory connectionFactory() {
return new ActiveMQConnectionFactory(JMS_BROKER_URL);
}
Run Code Online (Sandbox Code Playgroud)
任何帮助和代码示例都很有用.
提前致谢.GM
我是Spring Integration的新手.我让ActiveMQ说'responseQ'.所以当消息到达'responseQ' - > painResponseChannel - > transformer - > processResponseChannel - > beanProcessing时.我有以下设置:
<jms:message-driven-channel-adapter extract-payload="true"
channel="painResponseChannel"
connection-factory="connectionFactory"
destination-name="responseQ"/>
<integration:channel id="painResponseChannel" />
<integration-xml:unmarshalling-transformer
id="defaultUnmarshaller"
input-channel="painResponseChannel"
output-channel="processResponseChannel"
unmarshaller="marshaller"/>
<integration:channel id="processResponseChannel" />
<integration:service-activator
input-channel="processResponseChannel"
ref="processResponseActivator"/>
<bean id="processResponseActivator" class="com.messaging.processor.PainResponseProcessor"/>
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>com.domain.pain.Document</value>
</list>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
所以我的问题是我该如何测试结束?如何断言变压器的输出或断言通道上的什么?我尝试但失败了......希望有人可以提供帮助.
提前致谢.GM
我是这样测试的:在我的测试环境中创建了一个出站通道适配器,它使用testJmsQueue通道启动在activeMQ上发送消息.并且还为processResponseChannel - > testChannel创建了一个BRIDGE.我期待receive()方法能给我回馈一些东西.但我认为问题在于它太快了,当它到达receive()方法时,管道已经结束.
测试上下文如下所示:
<integration:bridge input-channel="processResponseChannel" output-channel="testChannel"/>
<jms:outbound-channel-adapter id="jmsOut" destination-name="responseQ" channel="testJmsQueue"/>
<integration:channel id="testJmsQueue"/>
<integration:channel id="testChannel">
<integration:queue/>
</integration:channel>
Run Code Online (Sandbox Code Playgroud)
然后在单元测试中我有这个:
@ContextConfiguration(locations = "classpath*:PainResponseTest-context.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class PainResponseTest {
private String painResponseXML;
@Autowired
MessageChannel …
Run Code Online (Sandbox Code Playgroud) 我正在使用Spring MVC
并返回JSON
作为响应。我想创建一个通用JSON
响应,我可以在其中输入任何类型并希望响应看起来像这样
{
status : "success",
data : {
"accounts" : [
{ "id" : 1, "title" : "saving", "sortcode" : "121212" },
{ "id" : 2, "title" : "current", "sortcode" : "445566" },
]
}
}
Run Code Online (Sandbox Code Playgroud)
所以我创建了一个Response<T>
对象
public class Response<T> {
private String status;
private String message;
T data;
...
...
}
Run Code Online (Sandbox Code Playgroud)
Spring
控制器中使用此 Response 对象来返回空响应对象和/或填充的响应对象。预先感谢 GM
更新:
为了获得JSON
与所描述的类似的输出,即使用“accounts”键JSON
,我必须Response<Map<String, List<Account>>>
在控制器中使用以下内容:
@RequestMapping(value = …
Run Code Online (Sandbox Code Playgroud) 我有一个变换器,它返回一个Map作为结果.然后将该结果放到输出通道上.我想要做的是为地图中的每个KEY转到不同的频道.如何在Spring Integration中配置它?
例如
变压器 - 生产 - >地图
地图包含{(Key1,"某些数据"),(Key2,"某些数据")}
所以对于Key1 - >转到频道1所以对于Key2 - >转到频道2等.
代码示例会很有帮助.
在此先感谢GM
我有多个核心的apache solr,例如货币,国家等...所以使用Spring Data Solr我可以从一个核心检索信息.我现在有这个XML配置对'货币'核心的查询.如果我想查询'country'核心我该如何设置它?
<!-- Enable Solr repositories and configure repository base package -->
<solr:repositories base-package="com.acme.repository" solr-template-ref="solrCurrencyTemplate"/>
<solr:solr-server id="solrCurrencyServer" url="http://localhost:8983/solr/currency"/>
<bean id="solrCurrencyTemplate" class="org.springframework.data.solr.core.SolrTemplate">
<constructor-arg ref="solrCurrencyServer" />
</bean>
Run Code Online (Sandbox Code Playgroud)
并将存储库定义为
@Repository
public interface CurrencyRepository extends SolrCrudRepository<Currency, String> {
}
Run Code Online (Sandbox Code Playgroud)
从我的服务我可以做到这一点
@Override
public List<Currency> getCurrencies() {
Page<Currency> currencies = (Page<Currency>) currencyRepository.findAll();
return currencies.getContent();
}
Run Code Online (Sandbox Code Playgroud)
我也试过使用@SolrDocument(solrCoreName ="currency"),但这不行.
@SolrDocument(solrCoreName = "currency")
public class Currency {
public static final String FIELD_CURRENCY_NAME = "currency_name";
public static final String FIELD_CURRENCY_CODE = "currency_code"; …
Run Code Online (Sandbox Code Playgroud)