首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jaxbmarshaller spring boot找不到bean?

jaxbmarshaller spring boot找不到bean?
EN

Stack Overflow用户
提问于 2016-11-23 07:04:27
回答 2查看 4.8K关注 0票数 0

我正在尝试在一个jaxbmarshaler中自动写入,以便在我的spring boot应用程序中使用。这似乎不符合编组员的要求。下面是我目前所拥有的,任何我遗漏的tipson

Maven依赖:

代码语言:javascript
复制
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-oxm</artifactId>
</dependency>

--- code

@Component

    public class DoSomethingService {

        @Autowired
        private Jaxb2Marshaller marshaller;
        marshaller.marshal(MyObject,Stringwriter)

我得到的错误是说它找不到Jaxb2Marsaller的bean,有什么想法吗?

EN

回答 2

Stack Overflow用户

发布于 2016-11-23 07:12:06

为了使用自动连接,您首先需要创建一个Marshaller bean,将必要的类/包指向Marshaller。然后你就可以注射它了。

票数 0
EN

Stack Overflow用户

发布于 2016-11-23 07:34:39

您需要有一个或多个配置类,其中应该定义所有可用于自动装配的bean。它类似于在spring应用程序上下文xml中定义bean

代码语言:javascript
复制
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"/>

在java config中:

代码语言:javascript
复制
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;

@Configuration
public class SomeName{
@Bean
    public Jaxb2Marshaller marshaller() {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        //any setters
        return marshaller;
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40753270

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档