消耗SOAP Web服務(wù)錯(cuò)誤(未注冊(cè)封送處理程序請(qǐng)檢查WebServiceTemplate的配置)
在這種情況下,我無(wú)法像我一樣在Controller中實(shí)例化一個(gè)新對(duì)象:
ProcuraPMPorREClient pm = new ProcuraPMPorREClient();
代替此,我需要?jiǎng)?chuàng)建一個(gè)@Autowired對(duì)象,如下所示:
@Autowired ProcuraPMPorREClient pm;
之后,我只調(diào)用相同的例程:
ProcuraPMPorREResponse response = pm.getPMPorRE(123456); System.out.println(response.getProcuraPMPorREResult().getNomePM());
這很好。
解決方法我遵循了入門-使用SOAP Web服務(wù)(https://spring.io/guides/gs/consumption-web-service/)來(lái)使用特定的Web服務(wù),并且一切正常:
我做了配置類:
@Configurationpublic class PMConfiguration { @Bean public Jaxb2Marshaller marshaller() {Jaxb2Marshaller marshaller = new Jaxb2Marshaller();// this package must match the package in the <generatePackage> specified in// pom.xmlmarshaller.setContextPath('com.inteligenciaweb.wsdl');return marshaller; } @Bean public ProcuraPMPorREClient procuraPMPorREClient(Jaxb2Marshaller marshaller) {ProcuraPMPorREClient client = new ProcuraPMPorREClient();client.setDefaultUri('http://tempuri.org/procuraPMPorRE');client.setMarshaller(marshaller);client.setUnmarshaller(marshaller);return client; }
}
客戶:
public class ProcuraPMPorREClient extends WebServiceGatewaySupport { private static final Logger log = LoggerFactory.getLogger(ProcuraPMPorRE.class); public ProcuraPMPorREResponse getPMPorRE(Integer RE) {ProcuraPMPorRE request = new ProcuraPMPorRE();request.setPMRENum(RE);log.info('Requesting PM for ' + RE);ProcuraPMPorREResponse response = (ProcuraPMPorREResponse) getWebServiceTemplate().marshalSendAndReceive('http://webservices.externo.policiamilitar.sp.gov.br:8071/router/wsscpm/basic',request,new SoapActionCallback('http://tempuri.org/procuraPMPorRE'));return response; }}
在課堂上申請(qǐng):
@SpringBootApplicationpublic class InteligenciawebApplication { public static void main(String[] args) {SpringApplication.run(InteligenciawebApplication.class,args); } @Bean CommandLineRunner lookup(ProcuraPMPorREClient pm) {return args -> { Integer re = 123456; ProcuraPMPorREResponse response = pm.getPMPorRE(re); System.err.println(response.getProcuraPMPorREResult().getNomeBancoPM());}; }}
啟動(dòng)應(yīng)用程序時(shí),weservice調(diào)用工作正常,因此可以在控制臺(tái)上查看結(jié)果。我嘗試使用相同的邏輯在其他類中調(diào)用此Web服務(wù),但無(wú)法正常工作。例如,我已經(jīng)在ControllerClass上進(jìn)行了測(cè)試:
@RequestMapping(value = '/soap',method = RequestMethod.GET)public String testeSoap() { ProcuraPMPorREClient pm = new ProcuraPMPorREClient(); ProcuraPMPorREResponse response = pm.getPMPorRE(123456); System.out.println(response.getProcuraPMPorREResult().getNomePM()); return null;}
在這種情況下,Web服務(wù)將無(wú)法運(yùn)行,并且系統(tǒng)將顯示以下錯(cuò)誤消息:java.lang.IllegalStateException:沒有注冊(cè)編組。檢查WebServiceTemplate的配置。我不知道為什么,但是Web服務(wù)只能在特定的地方工作,而不能在其他地方工作。如果有人知道會(huì)發(fā)生什么,我將不勝感激!謝謝!
相關(guān)文章:
1. 在應(yīng)用配置文件 app.php 中找不到’route_check_cache’配置項(xiàng)2. html按鍵開關(guān)如何提交我想需要的值到數(shù)據(jù)庫(kù)3. HTML 5輸入框只能輸入漢字、字母、數(shù)字、標(biāo)點(diǎn)符號(hào)?正則如何寫?4. javascript - 請(qǐng)教如何獲取百度貼吧新增的兩個(gè)加密參數(shù)5. Android中能不能判斷一個(gè)數(shù)據(jù)庫(kù)是create來(lái)的,還是open來(lái)的?6. gvim - 誰(shuí)有vim里CSS的Indent文件, 能縮進(jìn)@media里面的7. 跟著課件一模一樣的操作使用tp6,出現(xiàn)了錯(cuò)誤8. PHP類屬性聲明?9. javascript - 求助canvas繪制馬賽克的問題,老是取色不準(zhǔn)10. java - 安卓接入微信登錄,onCreate不會(huì)執(zhí)行
