簡體   English   中英

Spring-使用Java配置為xml配置Jboss Intros?

[英]Spring - configure Jboss Intros for xml with java config?

我正在編寫Spring Web應用程序,並希望將我的對象轉換為不帶注釋的xml。 我知道使用xml config可以做到這一點:

<bean id="jaxb2Marshaller" class="software.bytepushers.userprofile.models.JaxbIntroductionsMarshaller">
        <property name="classesToBeBound">
            <list>
                <value>software.bytepushers.userprofile.models.Person</value>
             <value>software.bytepushers.userprofile.models.WebServiceResponse</value>
            </list>
        </property>
        <property name="jaxbContextProperties">
            <map>
                <entry>
                    <key>
                        <util:constant static-field="com.sun.xml.bind.api.JAXBRIContext.ANNOTATION_READER"/>
                    </key>

                    <bean class="org.jboss.jaxb.intros.IntroductionsAnnotationReader">
                        <constructor-arg ref="jaxbIntroductions"/>
                    </bean>
                </entry>
            </map>
        </property>
        <property name="schema" value="classpath:schemas/avs-pdf-query-request.xsd"/>
    </bean>

    <bean id="jaxbIntroductions" class="org.jboss.jaxb.intros.IntroductionsConfigParser"
          factory-method="parseConfig">
        <constructor-arg><value>classpath:spring/jaxb-intros-marshaller-mapping.xml</value></constructor-arg>
    </bean>

現在在我的webconfig.java中

@Bean
    public Jaxb2Marshaller jaxb2Marshaller() throws SAXException {
        org.springframework.core.io.Resource schema = new ClassPathResource("schemas/person-schema.xsd");

        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        marshaller.setClassesToBeBound(new Class[]{Person.class});
        marshaller.setSchema(schema);

        return marshaller;
    }

我知道我的Java配置中缺少很多東西,我是Java配置的新手,並且找不到很多有關如何執行此操作的文檔。

任何幫助將不勝感激!

當xml config到java config中缺少給定項目的文檔時,最好的朋友是找到所涉及類的javadocs,在這種情況下:

@Bean javadocJaxb2Marshaler javadocJAXBRIContext javadoc ,並且找不到IntroductionsConfigParser和IntroductionsAnnotationReader的javadoc,也許需要對Red Hat的有效訂閱? 對此不確定。

我從來沒有親自使用過這些類,所以也許會有錯誤,但是我的第一次嘗試看起來像這樣:

@Bean(name = "jaxb2Marshaller")
public JaxbIntroductionsMarshaller jaxb2Marshaller() throws SAXException {
    JaxbIntroductionsMarshaller marshaller = new JaxbIntroductionsMarshaller ();

    marshaller.setClassesToBeBound(new Class[] {
            Person.class,
            WebServiceResponse.class
        });

    Map<String,Object> jaxbContextProperties = new HashMap<String,Object>();
    jaxbContextProperties.put(JAXBRIContext.ANNOTATION_READER, introductionsAnnotationReader());
    marshaller.setJaxbContextProperties(jaxbContextProperties);

    Resource schema = new ClassPathResource("schemas/avs-pdf-query-request.xsd");
    marshaller.setSchema(schema);

    return marshaller;
}

@Bean
public IntroductionsAnnotationReader introductionsAnnotationReader() {
    return new IntroductionsAnnotationReader(parseConfig());
}

現在還不確定工廠方法,因此我將發布2種可能的選擇:

@Bean(name = "jaxbIntroductions") // bean id
public IntroductionsConfigParser parseConfig() { // factory-method
   return new IntroductionsConfigParser( /* classpath:spring/jaxb-intros-marshaller-mapping.xml, Resource or String?? lack of javadoc */ );
}

要么

@Bean(name = "jaxbIntroductions") // bean id
public IntroductionsConfigParser parseConfig() {
   return IntroductionsConfigParser.parseConfig( /* Resource or String?? lack of javadoc */ );
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM