@wenshao 你好,想跟你请教个问题:
使用druid进行sql server 2008 数据源配置时异常,在oschina上查找了,好像还没有同学使用sql server 进行数据源配置
配置如下
<bean id="druidDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <!-- 基本属性配置 --> <property name="url" value="${datasource.url}"/> <property name="username" value="${datasource.username}"/> <property name="password" value="${datasource.password}"/> <!-- 配置初始化大小、最小、最大 --> <property name="initialSize" value="10" /> <property name="minIdle" value="5" /> <property name="maxActive" value="20" /> <!-- 配置获取连接等待超时的时间 --> <property name="maxWait" value="60000" /> <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> <property name="timeBetweenEvictionRunsMillis" value="60000" /> <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> <property name="minEvictableIdleTimeMillis" value="300000" /> <!-- <property name="validationQuery" value="SELECT 'x'" /> <property name="testWhileIdle" value="true" /> <property name="testOnBorrow" value="false" /> <property name="testOnReturn" value="false" /> --> <!-- 打开PSCache,并且指定每个连接上PSCache的大小 <property name="poolPreparedStatements" value="false" /> <property name="maxPoolPreparedStatementPerConnectionSize" value="20" /> --> <!-- 配置监控统计拦截的filters --> <property name="filters" value="stat,wall" /> <!-- 合并sql --> <property name="proxyFilters"> <list> <ref bean="stat-filter"/> </list> </property> </bean>
抛出错误信息如下:
SEVERE: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'druidDataSource' defined in URL [file:/D:/tomcat/webapps/ZDHKProject/WEB-INF/classes/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: dbType not support : null, url jdbc:sqlserver://localhost:1433;databaseName=zkdb at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1113) at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1671) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:724) Caused by: java.lang.IllegalStateException: dbType not support : null, url jdbc:sqlserver://localhost:1433;databaseName=zkdb at com.alibaba.druid.wall.WallFilter.init(WallFilter.java:130) at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:511) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1581) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1522) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452) ... 26 more
这是是因为WallFilter识别不到你这个是sqlserver引起的,配置中加入:
<property name="dbType" value = "sqlserver" />
######非常感谢,问题已解决。######用过且没有问题,看样子,url错误了,参考下面的 ,另外jar用sqljdbc4,还有删除安全文件,不然会出问题编译过去,有问题留言:
################################## # MS SQL Server 2000 (Microsoft) # com.microsoft.jdbc.sqlserver.SQLServerDriver ################################## jdbc.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver jdbc.url=jdbc:sqlserver://XXXXX:1433;database=XXXX jdbc.username=XXX jdbc.password=XXXX######
你看我这dbcp配置运行没有任何问题,换乘druid就抛错
######回复 @石头哥哥 : 配置了,驱动也是sqljdb4.jar,还是不行,一直提示dbType为空######建议你重新在配置中设置driverClass ,另外驱动用sqljdbc4,这样应该就可以了######升级新版本:druid-0.2.26,同时配置中制定driverLcassName######
你好,我配置了driverClassName 如下图
任然抛出异常,然后我跟了程序发现是在jdbcUtil中的方法
解析的时候匹配和我配置的url不同,我配置的url如下,
jdbc:sqlserver://localhost:1433;databaseName=zkdb开头是" jdbc:sqlserver",而不是" jdbc:microsoft:"
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。