- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Spring 4.0 中遇到转换服务问题如何在转换器中调用转换服务?
我的配置:
@Configuration
@ComponentScan...
@EnableAspectJAutoProxy
@EnableWebMvc
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Autowired
private Converter1 converter1;
@Autowired
private Converter2 converter2;
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(converter1);
registry.addConverter(converter2);
}
.....
}
我的转换器:
@Component
public class Converter1 implements Converter <SourceObject, TargetObjec>{
@Autowired
private org.springframework.core.convert.ConversionService conv
@Override
public TargetObjec convert(SourceObject source) {
.......
conv.convert(source.childObject, Target2.class);
}
}
@Component
public class Converter2 implements Converter <ChildObject, Target2>{
@Override
public TargetObjec2 convert(ChildObject source) {
.......
}
}
在 Controller 中我收到SourceObject
@Controller
public class SourceObjectReciver {
@Autowired
ConversionService conv;
@RequestMapping(value="/new", method={RequestMethod.POST})
@ResponseBody
public ResponseEntity<InterfaceStatus> createObject(@RequestBody SourceObject source, BindingResult br) {
conv.convert(source, TargetObjec.class);
...
}
}
TargetObject
和 ChildObject
是一个实体,并且它们是相关的
.......
public class TargetObject ....{
......
private ChildObject child;
}
Tomcat 无法加载 Web 应用程序,我遇到错误
>
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webMvcConfig': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private converter.Converter1 it.equipnet.GFInterface.config.WebMvcConfig.Converter1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Converter1': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.core.convert.ConversionService converter.Converter1.conv; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConversionService' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.format.support.FormattingConversionService org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.mvcConversionService()] threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5014)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5524)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private converter.Converter1 config.WebMvcConfig.Converter1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Converter1': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.core.convert.ConversionService converter.Converter1.conv; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConversionService' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.format.support.FormattingConversionService org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.mvcConversionService()] threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
... 22 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Converter1': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.core.convert.ConversionService converter.Converter1.conv; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConversionService' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.format.support.FormattingConversionService org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.mvcConversionService()] threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1014)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:957)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:855)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)
... 24 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.core.convert.ConversionService converter.Converter1.conv; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConversionService' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.format.support.FormattingConversionService org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.mvcConversionService()] threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
... 35 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConversionService' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.format.support.FormattingConversionService org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.mvcConversionService()] threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:592)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1014)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:957)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:855)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)
... 37 more
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.format.support.FormattingConversionService org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.mvcConversionService()] threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:188)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:581)
... 49 more
Caused by: java.lang.NullPointerException
at org.springframework.core.convert.support.GenericConversionService.getRequiredTypeInfo(GenericConversionService.java:270)
at org.springframework.core.convert.support.GenericConversionService.addConverter(GenericConversionService.java:84)
at it.equipnet.GFInterface.config.WebMvcConfig.addFormatters(WebMvcConfig.java:47)
at org.springframework.web.servlet.config.annotation.WebMvcConfigurerComposite.addFormatters(WebMvcConfigurerComposite.java:49)
at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration.addFormatters(DelegatingWebMvcConfiguration.java:100)
at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.mvcConversionService(WebMvcConfigurationSupport.java:403)
at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerByCGLIB$$a7f438f4.CGLIB$mvcConversionService$20(<generated>)
at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerByCGLIB$$a7f438f4$$FastClassByCGLIB$$3ea3412c.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:326)
at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerByCGLIB$$a7f438f4.mvcConversionService(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
... 50 more
最佳答案
我自己找到了解决方案。在 webConfig 中我添加了代码
.......
public void addFormatters(FormatterRegistry registry) {
ConversionService conversionService = (ConversionService) registry;
om3000PickupConverter.setConv(conversionService);
registry.addConverter(objectConverter);
registry.addConverter(childConverter);
}
.....
在转换器1中我添加了
private ConversionService conv;
public void setConv(ConversionService conv) {
this.conv = conv;
}
当我调用 conv.converter 时,它会调用 Convert2 的正确方法
关于java - Spring Converter 复杂对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33698693/
我之前发布过question已得到答复,但我也需要对此进行查询。我有一个包含这样数据的表结构(日期格式为 dd/mm/yyyy)。 ID Account Number Unit Ad
我正在使用 React Native Calendars 并尝试为议程组件构建我的数据。 预期的数据结构是(一个对象) { '2012-05-22': [{text: 'item 1 - any j
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
两列城镇和优先级。 我需要对表进行排序,以便优先级=1的城镇排在第一位,并且不按名称 ASC 排序,而其余城镇则按名称 ASC 排序。 我该怎么做? 谢谢;) 更新 SELECT * FROM map
我有三个表“Hardware_model”、“Warehouse”和“Brand”,并且表以这种方式一起引用:Hardware_model 仓库Hardware_model 品牌 现在我要执行以下
我有一个 MySQL 表 (tbl_filters),包含 3 列:id、cat、val id 和 val 是数字,cat 是 varchar。每个 id 有多行。 我还有另一个包含多个列的表 (tb
我想获取字段的不同值,比方说:field1...这需要一个如下查询:“从表中选择不同的(字段1)” 但是,对于某些记录,field1 为空,并且还有另一列可以替代 field1,即 field2。对于
表 1 - 用户 id username items 1 Paul 1(0020);2(0001); 表 2 - 项目 id name 1 name_here 在我的用户的项目中,我输入了 2(000
我想连接同一个表 4 次以获取列的显示方式,我不确定是否可以在 1 个 SQL 语句中完成。 tbl_用户名 id username 1 Adam 2 Bob 3 Chris tbl_机
首先,我刚刚开始自己学习JS,没有任何编程经验,这意味着我仍然要了解这种出色的编程语言的基本构建模块。 我的问题与我编写的以下代码有关: let orderCount = 0; con
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 9 年前。 Improve t
我正在使用 XMAPP,MySQL 正在正常运行。在 phpMyAdmin 中,我不太明白这一点,所以我尝试在 PHP 中创建一个。使用此代码,它会告诉我数据库 benutzer。尽管我在 phpMy
是否有一种高效的算法可以找到平均度最大的子图(可能是图本身)? 最佳答案 The paper "Finding a Maximum-Density Subgraph" by Andrew Goldbe
目录 1、业务背景 2、场景分析 3、流程设计 1、业务流程 2、导入流程
我有 2 个表: 1) 包含自 1900 年 1 月 1 日以来所有日期的 Masterdates 表 2) Stockdata 表,其中包含表单中的股票数据 日期、交易品种、开盘价、最高价、最低价、
我有一个非常复杂的 UI,其状态栏不断变化,其中包含多种类型的状态消息,并且 UI 具有复杂的图表控件和已加载的指示性地理 map 。 现在这些小而复杂的区域的数据上下文具有同样复杂的 ViewMod
有人可以用简单的方式向我解释为什么常量在大 O 表示法中无关紧要吗?为什么添加常量时复杂性保持不变。这不是作业问题,我只是想更好地理解这一点。让我明白这个大 O 是为了看到一个函数在接近无穷大时的行为
我在 flex 搜索索引中有以下文档。 [{ "_index": "ten2", "_type": "documents", "_id": "c323c
我有一个以零碎的方式构建的 LINQ 查询,如下所示: var initialQuery = from item in MyContext where xxx == yyy select item;
我目前正在涉足 SQL,并且希望针对我所创建的问题获得一些帮助。 为了练习一些编程,我正在制作一个 IOU 应用程序。下面是我存储的表我的借条记录(忽略一些相关栏目)。该表允许用户说“嘿,你欠我 X
我是一名优秀的程序员,十分优秀!