私はあまりにも問題があります。1:debbuging restTemplate、2:xmlをpojoにマッピングします。スプリング3を使って休止テンプレートを使ってpojoクラスにxmlをマップする方法は?
<parent>
<user id="23" name="name">
<registrationdate>2012-02-27T13:08:31.771-05:00</registrationdate>
</user>
</parent>
Iユーザー春3:私のようにXMLデータを返す別のWebサービスを持っている別のPOJO
@XmlRootElement(name = "user")
public class User {
public User(){
}
private long id;
private String name;
private Date registrationDate;
}
@XmlRootElement(name = "parent")
public class Parent {
private User user;
public Parent(){
}
//getter setter
}
:ここ
は私のコード POJOです私のクラスパスにはjaxb-apiとjaxb-implがあります:私は持っている私のappilacationコンテキストで:<bean id="restTemplate" class="org.springframework.web.client.RestTemplate"/>
と私は私のサービス層で:
@Service
public class ParentServiceI implements ParentService{
Logger logger = Logger.getLogger(this.getClass());
@Autowired
private RestTemplate restTemplate;
public Parent getMoreInfo() {
logger.info("getting info");
Parent p = restTemplate.getForObject("http://localhost:3128/dadad.xml", Parent.class);
logger.info(p.toString());
return p;
}}
私の最初の問題:私はこのコードを始めたとき は、私は確かにマッピングに問題がありました、
09:31:50,503 INFO [email protected] ParentServiceI :64 - getting info
09:31:50,670 DEBUG [email protected] client.RestTemplate:78 - Created GET request for "http://localhost:3128/dadad.xml"
09:31:50,971 DEBUG [email protected] client.RestTemplate:520 - Setting request Accept header to [application/xml, text/xml, application/*+xml, application/json]
09:31:58,762 DEBUG [email protected] client.RestTemplate:465 - GET request for "http://localhost:3128/dadad.xml" resulted in 200 (OK)
09:31:58,764 DEBUG [email protected] client.RestTemplate:78 - Reading [com.mypackage.Parent] as "text/xml" using [org.springfr[email protected]7d6d4e3e]
そしてその:しかし、私はすべてのエラーログを見ることができ波平、デバッグをcouldntの、いずれかの例外は、私のコンソールに私はそれを取得します。エラーはありません。コードがちょうどそこに貼り付けられています。 最初のログメッセージ「取得中」が表示されました.2番目のログメッセージが表示されませんでした。 どのようにデバッグできますか?
私の第二の問題: POJO権を設定した後、私はいくつかの結果を得た:
09:31:50,503 INFO [email protected] ParentServiceI :64 - getting info
09:31:50,670 DEBUG [email protected] client.RestTemplate:78 - Created GET request for "http://localhost:3128/dadad.xml"
09:31:50,971 DEBUG [email protected] client.RestTemplate:520 - Setting request Accept header to [application/xml, text/xml, application/*+xml, application/json]
09:31:58,762 DEBUG [email protected] client.RestTemplate:465 - GET request for "http://localhost:3128/dadad.xml" resulted in 200 (OK)
09:31:58,764 DEBUG [email protected] client.RestTemplate:78 - Reading [com.mypackage.Parent] as "text/xml" using [org.springfr[email protected]7d6d4e3e]
09:31:59,337 INFO [email protected] serviceI.EquipmentServiceI:83 - Parent [user=User [id=0, name=null, registrationDate=Mon Feb 27 13:08:31 EST 2012]]
everthingは、マッピングeccept罰金ですか? どうすれば修正できますか?
は、アプリケーションのコンテキストファイルで
としてゲッターに注釈を追加する必要がありますが、非整列化親オブジェクトのエントリを持っていないことをマップする
? – Waqas
いいえ。クラスパス内のrestTemplate beanとjaxb jarだけです。アンマーシャリングのエントリはどのように見えるのでしょうか? –