Required Multiple beans of same type in Spring

后端 未结 3 551
忘掉有多难
忘掉有多难 2020-12-04 18:18

A request before you mark it as duplicate. I have gone through the forum and couldn\'t find the solution for the problem anywhere.

I am writing a code using Spring 3

3条回答
  •  清歌不尽
    2020-12-04 18:49

    The Jaxb2Marshaller is perfectly capable to work with multiple different contexts/xsd. Simply specify multiple context paths by using the setContextPaths methods.

    @Bean(name="A1Unmarshaller")
    public Jaxb2Marshaller A1Unmarshaller(){
        Jaxb2Marshaller unMarshaller = new Jaxb2Marshaller();
        unMarshaller.setContextPaths(
            "package name for the classes generate by XSD A1",
            "package name for the classes generate by XSD A2",
            "package name for the classes generate by XSD A3",
            "package name for the classes generate by XSD A4",
            "package name for the classes generate by XSD A5" );
        return unMarshaller;
    }
    

    That way you only need a single marshaller/unmarshaller.

    Links

    1. Jaxb2Marshaller javadoc
    2. setContextPaths javadoc

提交回复
热议问题