ELK系列(4) - Elasticsearch cannot write xcontent for unknown value of type class java.math.BigDecimal

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/lewky_liu/article/details/88556755

问题与分析

在使用Elasticsearch进行index数据时,发现报错如下:

java.lang.IllegalArgumentException: cannot write xcontent for unknown value of type class java.math.BigDecimal
	at org.elasticsearch.common.xcontent.XContentBuilder.unknownValue(XContentBuilder.java:755)
	at org.elasticsearch.common.xcontent.XContentBuilder.value(XContentBuilder.java:726)
	at org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:711)
	at org.elasticsearch.index.query.BaseTermQueryBuilder.doXContent(BaseTermQueryBuilder.java:154)
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:82)
	at org.elasticsearch.index.query.BoolQueryBuilder.doXArrayContent(BoolQueryBuilder.java:275)
	at org.elasticsearch.index.query.BoolQueryBuilder.doXContent(BoolQueryBuilder.java:256)
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:82)
	at org.elasticsearch.common.xcontent.XContentBuilder.value(XContentBuilder.java:779)
	at org.elasticsearch.common.xcontent.XContentBuilder.value(XContentBuilder.java:772)
	at org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:764)
	at org.elasticsearch.search.builder.SearchSourceBuilder.toXContent(SearchSourceBuilder.java:1184)
	at org.elasticsearch.common.xcontent.XContentHelper.toXContent(XContentHelper.java:349)
	at org.elasticsearch.search.builder.SearchSourceBuilder.toString(SearchSourceBuilder.java:1558)
	at org.elasticsearch.search.builder.SearchSourceBuilder.toString(SearchSourceBuilder.java:1553)
	at java.lang.String.valueOf(String.java:2994)
	at java.lang.StringBuilder.append(StringBuilder.java:131)
	at org.elasticsearch.action.search.SearchRequest.toString(SearchRequest.java:516)

从异常信息看,显然ES无法接受BigDecimal类型,经过百度,也确实如此。在一篇博文评论中解释如下:

应该是客户端代码里将查询的数值定义成了java.math.BigDecimal,而ES不支持这个类型。之所以2.2没有问题,是因为之前的transport client发送数据之前将其序列化成了json,而在5.x以后,使用的内部的transport protocol,数据类型如果不匹配会抛错误。

所以数据类型的定义上,需要使用ES支持的类型。

解决方案

方案一:转变成其他ES支持的数据类型

我使用的是6.4.2版本的Elasticsearch,该版本尚不支持BigDecimal或者BigInteger的数据类型,所以在index到Elasticsearch之前,需要转换成其他数据类型,这里要注意不要数据溢出了:

  1. BigDecimal要转变成Double类型
  2. BigInteger要转变成Long类型

方案二:使用更高版本的ES

我在看6.7.1版本的Elasticsearch源码时发现已经可以支持BigDecimal或者BigInteger的数据类型了,所以直接使用该版本或更高版本的就行了。

下面附上两个版本的支持的数据类型的源码:

  • 6.4.2版本的Elasticsearch相关源码
Map<Class<?>, Writer> writers = new HashMap<>();
writers.put(Boolean.class, (b, v) -> b.value((Boolean) v));
writers.put(Byte.class, (b, v) -> b.value((Byte) v));
writers.put(byte[].class, (b, v) -> b.value((byte[]) v));
writers.put(Date.class, XContentBuilder::timeValue);
writers.put(Double.class, (b, v) -> b.value((Double) v));
writers.put(double[].class, (b, v) -> b.values((double[]) v));
writers.put(Float.class, (b, v) -> b.value((Float) v));
writers.put(float[].class, (b, v) -> b.values((float[]) v));
writers.put(Integer.class, (b, v) -> b.value((Integer) v));
writers.put(int[].class, (b, v) -> b.values((int[]) v));
writers.put(Long.class, (b, v) -> b.value((Long) v));
writers.put(long[].class, (b, v) -> b.values((long[]) v));
writers.put(Short.class, (b, v) -> b.value((Short) v));
writers.put(short[].class, (b, v) -> b.values((short[]) v));
writers.put(String.class, (b, v) -> b.value((String) v));
writers.put(String[].class, (b, v) -> b.values((String[]) v));
writers.put(Locale.class, (b, v) -> b.value(v.toString()));
writers.put(Class.class, (b, v) -> b.value(v.toString()));
writers.put(ZonedDateTime.class, (b, v) -> b.value(v.toString()));
writers.put(Calendar.class, XContentBuilder::timeValue);
writers.put(GregorianCalendar.class, XContentBuilder::timeValue);
  • 6.7.1版本的Elasticsearch相关源码
Map<Class<?>, Writer> writers = new HashMap<>();
writers.put(Boolean.class, (b, v) -> b.value((Boolean) v));
writers.put(Byte.class, (b, v) -> b.value((Byte) v));
writers.put(byte[].class, (b, v) -> b.value((byte[]) v));
writers.put(Date.class, XContentBuilder::timeValue);
writers.put(Double.class, (b, v) -> b.value((Double) v));
writers.put(double[].class, (b, v) -> b.values((double[]) v));
writers.put(Float.class, (b, v) -> b.value((Float) v));
writers.put(float[].class, (b, v) -> b.values((float[]) v));
writers.put(Integer.class, (b, v) -> b.value((Integer) v));
writers.put(int[].class, (b, v) -> b.values((int[]) v));
writers.put(Long.class, (b, v) -> b.value((Long) v));
writers.put(long[].class, (b, v) -> b.values((long[]) v));
writers.put(Short.class, (b, v) -> b.value((Short) v));
writers.put(short[].class, (b, v) -> b.values((short[]) v));
writers.put(String.class, (b, v) -> b.value((String) v));
writers.put(String[].class, (b, v) -> b.values((String[]) v));
writers.put(Locale.class, (b, v) -> b.value(v.toString()));
writers.put(Class.class, (b, v) -> b.value(v.toString()));
writers.put(ZonedDateTime.class, (b, v) -> b.value(v.toString()));
writers.put(Calendar.class, XContentBuilder::timeValue);
writers.put(GregorianCalendar.class, XContentBuilder::timeValue);
writers.put(BigInteger.class, (b, v) -> b.value((BigInteger) v));
writers.put(BigDecimal.class, (b, v) -> b.value((BigDecimal) v));

可以发现,在6.7.1版本的源码里,多出了最后的两种数据类型的支持:BigInteger和BigDecimal。

参考链接

展开阅读全文

classcannot be resolved to a type

10-20

jsp页面 编译报如标题错误 jsp文件全部在tomcat的root目录下 “class”也在相同目录下的一个.Java的文件中定义 jsp页面中也 通过<%@ page import = "com.ftsafe.util.*"%>引用 不知为何 大侠帮忙 感激涕零!页面代码如下:rnrn<%@ page language="java" contentType="text/html;charset=gb2312" %>rn<%@ page session="true" %>rn<%@ page import="java.io.*"%>rn<%@ page import = "com.ftsafe.util.*"%>rn<%@ page import="java.sql.*"%> rnrnrnrn<%rn String Randata = (String)session.getAttribute("RandomData");rnrn String ClientDigest = request.getParameter("Digest");rn rn rn rn /*如数据库中用户ID是中文需要转换rn //String UserID = new String(UserID1.getBytes("ISO8859_1"),"GB2312");rn //out.println(UserID);rn //out.println(ClientDigest);*/rnrn String UserKey=""; /*从数据库中得到的用户密钥,用于计算。硬件中的密钥文件是由该密钥产生的。是初始化工具完成的*/rn String ServerDigest=""; /*服务器端计算的结果*/rn byte digest[];rn rn UserKey = "123456"; /*由于数据库各处不同,通过查找后得赋值到UserKey中,示例为:“123456”*/rnrnrn rn Integer i = new Integer(UserKey.length());rn out.println("密钥长度"+i.toString());rn rn rn rn HMAC_MD5 hm = new HMAC_MD5(UserKey.getBytes());rn hm.addData(Randata.getBytes());rn rn digest = hm.sign();rn ServerDigest = hm.toString();rn if(ClientDigest.equals(ServerDigest))rn rn out.println("ok,equal!");rn rn elsern rn out.println("Sorry,clentDigest doesn't equal Server Digest!");rn rn%>rnrn rn rn Randata:rn <%=Randata%>rn ClientDigest:<%=ClientDigest%>rn rn rn UserKey:rn <%=UserKey%>rn ServerDigest:<%=ServerDigest%>rn rnrnrnrnrn 论坛

java.lang.IllegalArgumentException: Cannot convert value of type [com.ssh.dao.im

08-16

rnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [com.ssh.dao.impl.UserDAO] to required type [com.ssh.dao.IUserDAO] for property 'userDAO'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [com.ssh.dao.impl.UserDAO] to required type [com.ssh.dao.IUserDAO] for property 'userDAO': no matching editors or conversion strategy foundrn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:478)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)rn at java.security.AccessController.doPrivileged(Native Method)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:220)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)rn at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)rn at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)rn at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)rn at org.springframework.web.context.ContextLoaderServlet.init(ContextLoaderServlet.java:81)rn at javax.servlet.GenericServlet.init(GenericServlet.java:212)rn at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)rn at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)rn at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4042)rn at org.apache.catalina.core.StandardContext.start(StandardContext.java:4348)rn at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)rn at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)rn at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)rn at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)rn at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)rn at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)rn at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)rn at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)rn at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)rn at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)rn at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)rn at org.apache.catalina.core.StandardService.start(StandardService.java:516)rn at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)rn at org.apache.catalina.startup.Catalina.start(Catalina.java:566)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn at java.lang.reflect.Method.invoke(Unknown Source)rn at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)rn at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)rnCaused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [com.ssh.dao.impl.UserDAO] to required type [com.ssh.dao.IUserDAO] for property 'userDAO'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [com.ssh.dao.impl.UserDAO] to required type [com.ssh.dao.IUserDAO] for property 'userDAO': no matching editors or conversion strategy foundrn at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:391)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1287)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1248)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1008)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:470)rn ... 41 morernCaused by: java.lang.IllegalArgumentException: Cannot convert value of type [com.ssh.dao.impl.UserDAO] to required type [com.ssh.dao.IUserDAO] for property 'userDAO': no matching editors or conversion strategy foundrn at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:219)rn at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)rn at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386)rn ... 45 morern2011-8-16 23:07:33 org.apache.catalina.core.StandardContext loadOnStartuprn严重: Servlet /ssh threw load() exceptionrnjava.lang.IllegalArgumentException: Cannot convert value of type [com.ssh.dao.impl.UserDAO] to required type [com.ssh.dao.IUserDAO] for property 'userDAO': no matching editors or conversion strategy foundrn at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:219)rn at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)rn at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1287)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1248)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1008)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:470)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)rn at java.security.AccessController.doPrivileged(Native Method)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:220)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)rn at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)rn at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)rn at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)rn at org.springframework.web.context.ContextLoaderServlet.init(ContextLoaderServlet.java:81)rn at javax.servlet.GenericServlet.init(GenericServlet.java:212)rn at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)rn rnrnSSH 框架搭建, 是启动异常 。 rn请问 是大小写的问题么, 能具体到啥问题么, 找了半天 都没找到 论坛

java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource]

09-24

启动tomcat我这里就报rn它抛出 rn严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener rnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource': no matching editors or conversion strategy found rnCaused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource': no matching editors or conversion strategy found rnCaused by: java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource': no matching editors or conversion strategy found rnat org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:231) rnat org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138) rnat org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:380) rnat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1107) rnat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857) rnat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:423) rnat org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249) rnat org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155) rnat org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246) rnat org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160) rnat org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:285) rnat org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352) rnat org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:245) rnat org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:188) rnat org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49) rnat org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843) rnat org.apache.catalina.core.StandardContext.start(StandardContext.java:4350) rnat org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791) rnat org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771) rnat org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525) rnat org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:924) rnat org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:887) rnat org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492) rnat org.apache.catalina.startup.HostConfig.start(HostConfig.java:1147) rnat org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311) rnat org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117) rnat org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053) rnat org.apache.catalina.core.StandardHost.start(StandardHost.java:719) rnat org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) rnat org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) rnat org.apache.catalina.core.StandardService.start(StandardService.java:516) rnat org.apache.catalina.core.StandardServer.start(StandardServer.java:710) rnat org.apache.catalina.startup.Catalina.start(Catalina.java:578) rnat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) rnat sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) rnat sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) rnat java.lang.reflect.Method.invoke(Unknown Source) rnat org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288) rnat org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413) rn这个异常 rn这个是applicationContent.xml中sessionFactory bean rn rn rn rn rn rn rncom/v512/guestbook/model/Guestbook1.hbm.xml rn rn rn rn rnorg.hibernate.dialect.Oracle9Dialect rn rn rnrnrn我dataSource配置是WEB-INF/web.xml rnrnrn请高手指点迷津。 论坛

关于java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource]

09-21

它抛出rn严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerrnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource': no matching editors or conversion strategy foundrnCaused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource': no matching editors or conversion strategy foundrnCaused by: java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource': no matching editors or conversion strategy foundrn at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:231)rn at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)rn at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:380)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1107)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:423)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:285)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)rn at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:245)rn at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:188)rn at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)rn at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)rn at org.apache.catalina.core.StandardContext.start(StandardContext.java:4350)rn at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)rn at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)rn at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)rn at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:924)rn at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:887)rn at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)rn at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1147)rn at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)rn at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)rn at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)rn at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)rn at org.apache.catalina.core.StandardService.start(StandardService.java:516)rn at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)rn at org.apache.catalina.startup.Catalina.start(Catalina.java:578)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn at java.lang.reflect.Method.invoke(Unknown Source)rn at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)rn at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)rn这个异常rn这个是applicationContent.xml中sessionFactory beanrnrn rn rn rn rn rn com/v512/guestbook/model/Guestbook1.hbm.xmlrn rn rn rn rn org.hibernate.dialect.Oracle9Dialectrn rn rn 论坛

The type com.sun.star.lang.XEventListener cannot be resolved.

04-12

报错:The type com.sun.star.lang.XEventListener cannot be resolved. It is indirectly referenced from rn required .class filesrn后台报错:rnAllocate exception for servlet convertUtilrnjava.lang.Error: Unresolved compilation problem: rn The type com.sun.star.lang.XEventListener cannot be resolved. It is indirectly referenced from required .class filesrnrn at servlet.ConvertServlet.(ConvertServlet.java:1)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)rn at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)rn at java.lang.reflect.Constructor.newInstance(Constructor.java:513)rn at java.lang.Class.newInstance0(Class.java:355)rn at java.lang.Class.newInstance(Class.java:308)rn at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:119)rn at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1061)rn at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:812)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)rn at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)rn at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:284)rn at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:322)rn at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1699)rn at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)rn at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)rn at java.lang.Thread.run(Thread.java:619)rnrnrn高手帮忙看看哈! 论坛

Cannot marshal 'return value': Invalid managed/unmanaged type combination.

07-05

VS2010-C#引用delphi6下编译的dll文件,读出byte[]报错“Cannot marshal 'return value': Invalid managed/unmanaged type combination.”rndelphi6下编译的dll文件 源码如下:rnrn[code=Delphi(Pascal)]rnlibrary dataoutdll;rnusesrn Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,rn Dialogs, DB, ADODB, Grids, DBGrids, DBClient, StdCtrls, Provider;rnrntypern byteBuffer = array[0..1024] of byte;rnvarrnmydataset:tclientdataset;rnmydatasource:tdatasource;rnmyprovider: tdatasetprovider;rnmyquery:tadoquery;rnsqlcmd:TStringList;rnrnms1,ms2,ms3:TMemoryStream;rnbuf: bytebuffer;rn$R *.resrnfunction getbytes():bytebuffer;stdcall;rnbeginrnms1:=TMemoryStream.Create;rnms2:=TMemoryStream.Create;rnms3:=TMemoryStream.Create;rnrnrnmydataset:=tclientdataset.Create(nil);rnmydatasource:=tdatasource.Create(nil);rnmyprovider:=tdatasetprovider.Create(nil);rnmyquery:=tadoquery.Create(nil);rnsqlcmd:=tstringlist.Create;rnrnsqlcmd.Add('select * from trequestprice');rnmyquery .ConnectionString :=rn 'Provider=SQLNCLI.1;Password=qqqqqq;Persist Security Info=True;Us' +rn 'er ID=sa;Initial Catalog=HSEms;Data Source=.' ;rnmyquery .CursorType := ctStatic ;rnmyquery.SQL.AddStrings(sqlcmd) ;rnmyquery.SQL.Strings [0];rnmyquery .Active := True;rnrnmyprovider.DataSet :=myquery;rnmydataset.SetProvider(myprovider) ;rnmydataset.Active := True ;rnmydatasource.DataSet := mydataset;rnrnmydataset.SaveToStream(ms3);rnms3.Position :=0;rnrnFillChar(buf,1025,0);rnms3.Read (buf,sizeof(buf));rnms3.Position :=0;rnresult:=buf;rnend;rnExportsrngetbytes;rnrnbeginrnend.rn[/code]rn代码功能:读取表trequestprice到内存buf中,作为dll的返回值吐出给C#。rnrnVS2010-C#下调用该dll的代码如下:rn[code=C#]rn[DllImport("dataoutdll.dll", EntryPoint = "getbytes", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]rn public static extern byte[] getbytes();rnrn rn private void button1_Click(object sender, EventArgs e)rn rnrn tryrn rn byte[] mybt = new byte[1024];rn mybt = getbytes();//程序执行到这里报错rn rn catch (Exception ex)rn MessageBox.Show(ex .Message ); rn rn rn rn[/code]rnrn错误提示为:Cannot marshal 'return value': Invalid managed/unmanaged type combination.rnrn请问各位:delphi6编译下的dll中的array[0..1024] of byte 跟C#下的byte[1024],在内存上是等效的吗?rn如何解决这个错误?rn在线等。rn谢谢 论坛

没有更多推荐了,返回首页