开发者社区> 问答> 正文

Spring+hibernate+druid配置报错403.10 禁止访问:配置无效 

软件版本

Spring3.2.4、hibernate-4.2.5?、druid-0.2.26

配置如下
xml:

<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<!-- 配置Spring -->
<context-param>
	<param-name>contextConfigLocation </param-name>
	<param-value>classpath:applicationContext-*.xml	</param-value>
</context-param>

<!-- 配置Spring的过滤器,解决乱码问题 -->
<filter>
	<filter-name>encoding</filter-name>
	<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
	<init-param>
		<param-name>encoding</param-name>
		<param-value>UTF-8</param-value>
	</init-param>
</filter>
<filter-mapping>
	<filter-name>encoding</filter-name>
	<url-pattern>/*</url-pattern>
</filter-mapping>

<!-- 配置Spring的监听 -->
<listener>
	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- session 过期时间 -->
<session-config>
	<session-timeout>120</session-timeout>
</session-config>

<!-- 默认页面 -->
<welcome-file-list>
	<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

</web-app>

applicationContext-common.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
           http://www.springframework.org/schema/tx       http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
           http://www.springframework.org/schema/task
           http://www.springframework.org/schema/task/spring-task-3.2.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
	
	<bean id="myDataSource" class="com.alibaba.druid.pool.DruidDataSource"  init-method="init" destroy-method="close">
		<!-- 驱动名称 -->  
                <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
		<!-- JDBC连接串 -->  
		<property name="url" value="jdbc:oracle:thin:@192.168.1.213:1521:timdb" />  
		<!-- 数据库用户名称 -->
		<property name="username" value="tim"/>
		<!-- 数据库密码 -->  
		<property name="password" value="passw0rd"/> 
		 
		<property name="connectionProperties" value="config.decrypt=true"/>  
		<property name="filters" value="config" />
		  
		<!-- 初始化大小 -->  
                <property name="initialSize" value="15" />
		<!-- 连接池最大使用连接数量 -->  
                <property name="maxActive" value="20" />
                <!-- 连接池最小空闲 -->  
                <property name="minIdle" value="0" />
        
		<!-- 配置获取连接等待超时的时间 -->  
		<property name="maxWait" value="60000" />  
        
		<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->  
		<property name="timeBetweenEvictionRunsMillis" value="60000" />  
        		
		<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->  
		<property name="minEvictableIdleTimeMillis" value="300000" />  

		<!-- 测试有效用的SQL Query -->  
            <!-- <property name="validationQuery" value="SELECT 'x'" />  -->          
            <!-- 连接空闲时测试是否有效 -->  
            <property name="testWhileIdle" value="false" />  
            <!-- 获取连接时测试是否有效 -->  
            <property name="testOnBorrow" value="false" />  
            <!-- 归还连接时是否测试有效 -->  
            <property name="testOnReturn" value="false" />
        
		<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->  
		<property name="poolPreparedStatements" value="true" />  
		<property name="maxPoolPreparedStatementPerConnectionSize" value="20" /> 
	
	</bean>
	<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" > 
		<property name="dataSource" ref="myDataSource" />
		<property name="annotatedClasses">
            <list>
                <value>m.user.ObjectUser</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop>
            </props>
        </property>
        <property name="packagesToScan">
            <value>com.xxx.mobile.k.beans</value>
        </property>
	</bean>
	
	<!-- 事务 -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager" abstract="false" lazy-init="default" autowire="default">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>
	
	<!-- 自动启动Spring 事务的注解功能 -->
    <tx:annotation-driven />
    
	<!-- 自动启动Spring 定时器的注解功能 -->      
    <task:annotation-driven />
</beans>
报错信息如下

[ERROR] 2013/09/20 18:52:58.338 - Context initialization failed org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:319) org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myDataSource' defined in file [F:\Eclipse.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\Test\WEB-INF\classes\applicationContext-common.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to decrypt. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4205) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053) at org.apache.catalina.core.StandardHost.start(StandardHost.java:840) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463) at org.apache.catalina.core.StandardService.start(StandardService.java:525) at org.apache.catalina.core.StandardServer.start(StandardServer.java:754) at org.apache.catalina.startup.Catalina.start(Catalina.java:595) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414) Caused by: java.lang.IllegalArgumentException: Failed to decrypt. at com.alibaba.druid.filter.config.ConfigFilter.decrypt(ConfigFilter.java:211) at com.alibaba.druid.filter.config.ConfigFilter.init(ConfigFilter.java:123) at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:511) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1608) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1549) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479) ... 27 more Caused by: javax.crypto.BadPaddingException: Data must start with zero at sun.security.rsa.RSAPadding.unpadV15(RSAPadding.java:308) at sun.security.rsa.RSAPadding.unpad(RSAPadding.java:255) at com.sun.crypto.provider.RSACipher.a(DashoA13*..) at com.sun.crypto.provider.RSACipher.engineDoFinal(DashoA13*..) at javax.crypto.Cipher.doFinal(DashoA13*..) at com.alibaba.druid.filter.config.ConfigTools.decrypt(ConfigTools.java:147) at com.alibaba.druid.filter.config.ConfigFilter.decrypt(ConfigFilter.java:203) ... 36 more 2013-9-20 18:52:58 org.apache.catalina.core.StandardContext listenerStart 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myDataSource' defined in file [F:\Eclipse.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\Test\WEB-INF\classes\applicationContext-common.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to decrypt. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4205) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053) at org.apache.catalina.core.StandardHost.start(StandardHost.java:840) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463) at org.apache.catalina.core.StandardService.start(StandardService.java:525) at org.apache.catalina.core.StandardServer.start(StandardServer.java:754) at org.apache.catalina.startup.Catalina.start(Catalina.java:595) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414) Caused by: java.lang.IllegalArgumentException: Failed to decrypt. at com.alibaba.druid.filter.config.ConfigFilter.decrypt(ConfigFilter.java:211) at com.alibaba.druid.filter.config.ConfigFilter.init(ConfigFilter.java:123) at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:511) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1608) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1549) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479) ... 27 more Caused by: javax.crypto.BadPaddingException: Data must start with zero at sun.security.rsa.RSAPadding.unpadV15(RSAPadding.java:308) at sun.security.rsa.RSAPadding.unpad(RSAPadding.java:255) at com.sun.crypto.provider.RSACipher.a(DashoA13*..) at com.sun.crypto.provider.RSACipher.engineDoFinal(DashoA13*..) at javax.crypto.Cipher.doFinal(DashoA13*..) at com.alibaba.druid.filter.config.ConfigTools.decrypt(ConfigTools.java:147) at com.alibaba.druid.filter.config.ConfigFilter.decrypt(ConfigFilter.java:203) ... 36 more 2013-9-20 18:52:58 org.apache.catalina.core.StandardContext start 严重: Error listenerStart 2013-9-20 18:52:58 org.apache.catalina.core.StandardContext start 严重: Context [/Test] startup failed due to previous errors 2013-9-20 18:52:58 org.apache.catalina.core.ApplicationContext log 信息: Closing Spring root WebApplicationContext 2013-9-20 18:52:58 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc 严重: The web application [/Test] registered the JDBC driver [com.alibaba.druid.proxy.DruidDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. 2013-9-20 18:52:58 org.apache.coyote.http11.Http11Protocol start 信息: Starting Coyote HTTP/1.1 on http-81 2013-9-20 18:52:58 org.apache.jk.common.ChannelSocket init 信息: JK: ajp13 listening on /0.0.0.0:8010 2013-9-20 18:52:58 org.apache.jk.server.JkMain start 信息: Jk running ID=0 time=0/19  config=null 2013-9-20 18:52:58 org.apache.catalina.startup.Catalina start 信息: Server startup in 1070 ms 2013-9-20 18:53:00 org.apache.coyote.http11.Http11Protocol pause 信息: Pausing Coyote HTTP/1.1 on http-81 2013-9-20 18:53:01 org.apache.catalina.core.StandardService stop 信息: Stopping service Catalina 2013-9-20 18:53:01 org.apache.catalina.core.StandardContext stop 信息: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/Test] has not been started 2013-9-20 18:53:01 org.apache.coyote.http11.Http11Protocol destroy 信息: Stopping Coyote HTTP/1.1 on http-81

展开
收起
kun坤 2020-05-27 20:03:28 763 0
1 条回答
写回答
取消 提交回答
  • 没用过druid,但我看到了与其它配置参数格式很不合谐的一句:
    <property name="connectionProperties" value="config.decrypt=true"/>  凭感觉是这句出问题,你看看。######目测去了就好了######无法部署mydatasource 看起来像是数据库的用户名或密码错误######什么时代了, 还有人用hibernate######不用 hibernate 那现在用什么?######回复 @leh : 有些人专门以看不起ORM为荣######为什么不用,强烈建议用!######数据库密码好奇怪,是password吧字母o和数字0混了吧!######数据库用户名与密码没问题, 我用 c3p0连接都正常,换用 druid 就报错。###### 好用了,去掉
    <property name="connectionProperties" value="config.decrypt=true"/>   <property name="filters" value="config" /> <property name="annotatedClasses">             <list>                 <value>m.user.ObjectUser</value>             </list>         </property>

    ######

    引用来自“dnetcreate”的答案

    数据库用户名与密码没问题, 我用 c3p0连接都正常,换用 druid 就报错。
    那不就是druid的问题,你换一对密码试试,我怀疑是druid的加密解密算法导致的加密错误
    2020-05-28 14:52:13
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载

相关实验场景

更多