我完全是Spring的初学者(你可以在我的代码中看到:)).我只想测试RestTemplate类,但我得到了一个ClassNotFoundException.
所以代码是:
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.client.RestTemplate;
public class RestClient {
private RestTemplate restTemplate;
public String getJiraIssueAsJson(){
Object o = restTemplate.getForObject(..., Object.class);
System.out.println("..."+o.getClass());
return null;
}
public void setRestTemplate(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("rest-client-context.xml");
RestClient restClient = context.getBean("restClient", RestClient.class);
restClient.getJiraIssueAsJson();
}
}
Run Code Online (Sandbox Code Playgroud)
的context.xml
<beans ...>
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverte????r"/>
</list>
</property>
</bean>
<bean id="restClient" class="org.googlecode.happymarvin.jiraexplorer.RestClient">
<property name="restTemplate" ref="restTemplate"/>
</bean>
</beans>
Run Code Online (Sandbox Code Playgroud)
的pom.xml …
我想保留原始请求的原始有效负载,并且它是在xslt-transformer或其他操作中.我失去了它因为我使用了xslt-transformer而我只需要转换中的一些元素.所以我的方案是:
1.inbound-gateway(传入的WS req) - > 2.xslt-transformer(用于调用外部WS的映射) - > 3.outbound-gateway(调用外部WS) - > 4.xslt-transformer(创建响应来自分别是外部WS和原始的req)
在第四步我没有原始的req,但我需要它,因为我必须将它的值放到响应中.我怎么能实现它?
谢谢,V.
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration" xmlns:int-ws="http://www.springframework.org/schema/integration/ws" xmlns:int-xml="http://www.springframework.org/schema/integration/xml" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/integration/ws http://www.springframework.org/schema/integration/ws/spring-integration-ws.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/integration/xml http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<bean id="authenticator" class="uk.co.virginmedia.test.Authenticator"/>
<bean id="webserviceDestinationProvider" class="uk.co.virginmedia.test.WebserviceDestinationProvider"/>
<bean id="resultToDocumentTransformer" class="org.springframework.integration.xml.transformer.ResultToDocumentTransformer"/>
<util:map id="orderNamespaceMap">
<entry key="res" value="http://schema/ReserveAppointment/2/0" />
</util:map>
<int-ws:inbound-gateway id="ws-gateway-for-rbta" request-channel="incoming-req-channel" reply-channel=""/>
<int:channel id="incoming-req-channel"/>
<int:service-activator id="authentication" input-channel="incoming-req-channel" ref="authenticator" method="authenticate" output-channel="authenticated-channel" />
<int:channel id="authenticated-channel"/>
<int-xml:xpath-router id="servicetype-router" input-channel="authenticated-channel" evaluate-as-string="true">
<int-xml:xpath-expression expression="//res:ReserveAppointmentRequest/res:serviceType/text()" ns-prefix="res" ns-uri="http://schema/ReserveAppointment/2/0"/>
<int-xml:mapping value="Broadband" channel="broadband-channel"/>
<int-xml:mapping value="FTTC+WholesaleLineRental" channel="fttc-wlr-channel"/>
</int-xml:xpath-router>
<int:channel id="broadband-channel"/>
<int-xml:xslt-transformer …Run Code Online (Sandbox Code Playgroud) 我想对我的 java 日志条目进行分组,以便更轻松地在其中进行搜索。我的意思是有以下日志记录:
14-Mar-2012 14:29:07 com.acme.service.AcmeService log
INFO: Start ACME operation
14-Mar-2012 14:29:07 com.acme.service.AcmeService log
INFO: step 1 - do something
...
14-Mar-2012 14:29:07 com.acme.service.AcmeService log
INFO: End ACME operation
Run Code Online (Sandbox Code Playgroud)
这些记录彼此属于,因为它们是工作流程的步骤(例如,我想跟踪网络服务的流程)。是否有一个好的设计模式可以将这些记录组合在一起,以便我能够轻松找到 Web 服务请求的日志?(例如在所有日志条目的开头放置一个ID)?有没有一个工具可以将这些日志自动分组显示?类似于 log4j 电锯,但按此 id 分组?谢谢!
我使用@MockBean弹簧靴(带@RunWith(SpringRunner.class))到目前为止一切都很好.
然而,mock为mocked类的每个方法提供了默认实现,所以我无法检查是否只调用那些我希望被调用的方法,即我想创建严格的mock.
这有可能@MockBean吗?
如果有人知道如何只检查那些我预期的方法,我不会坚持创建严格的模拟.
我在这里先向您的帮助表示感谢!
问候,
V.
我使用 lombok,它真的很棒!但是,如果我打印包含 Calendar 属性的 bean,它会打印 Calendar 对象(当然......)并且看到 Calendar 的值真的很令人困惑。我可以看到类似的东西
ScheduledEvent(id=1, scheduledStartDate=java.util.GregorianCalendar[time=1492032183000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Budapest",offset=3600000,dstSavings=3600000,useDaylight=true,transitions=151,lastRule=java.util.SimpleTimeZone[id=Europe/Budapest,offset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2017,MONTH=3,WEEK_OF_YEAR=15,WEEK_OF_MONTH=3,DAY_OF_MONTH=12,DAY_OF_YEAR=102,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=2,AM_PM=1,HOUR=11,HOUR_OF_DAY=23,MINUTE=23,SECOND=3,MILLISECOND=0,ZONE_OFFSET=3600000,DST_OFFSET=3600000], ...
Run Code Online (Sandbox Code Playgroud)
是否可以以某种方式将 SimpleDateFormat 分配给 Calendar(例如,如果 lombok 遇到 Calendar 对象然后使用此格式化程序)并且具有像“2016-34-34T12:12:12.543”这样的简单值?
谢谢,
V。
我应该在webservice(EJB 3.0)中等待一段时间(一两秒钟).
我发现这个关于我的问题的问题似乎是EJB世界中唯一合法的解决方案,但我仍然找不到如何等待的解决方案.我经常搜索,但似乎用meg 3.0的工具无法实现.
真的吗?或者有解决方案吗?
java ×5
spring ×2
ejb-3.0 ×1
logging ×1
lombok ×1
maven ×1
mockito ×1
resttemplate ×1
spring-boot ×1