我有以下Mule应用程序,我试图通过Spring Security使用数据库来保护用户(jdbc-provider)。
我在Mule App的类路径中正确配置了mysql数据库和mysql jdbc驱动程序,但是当我尝试登录时,我收到以下错误:
无法获取JDBC连接;嵌套异常是java.sql.SQLException:没有为jdbc找到合适的驱动程序:mysql:// localhost:3306 / test(org.springframework.jdbc.CannotGetJdbcConnectionException) org.springframework.jdbc.datasource.DataSourceUtils:80(null)
Mule App(基于Mule ESB 3.6.1):
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mule-ss="http://www.mulesoft.org/schema/mule/spring-security"
xmlns:ss="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/spring-security http://www.mulesoft.org/schema/mule/spring-security/3.1/mule-spring-security.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
http://www.mulesoft.org/schema/mule/tls http://www.mulesoft.org/schema/mule/tls/current/mule-tls.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.mulesoft.org/schema/mule/https http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd">
<spring:beans>
<spring:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<spring:property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<spring:property name="url" value="jdbc:mysql://localhost:3306/test"/>
<spring:property name="username" value="root"/>
<spring:property name="password" value="sonar"/>
</spring:bean>
<ss:authentication-manager alias="authenticationManager">
<ss:authentication-provider>
<ss:jdbc-user-service data-source-ref="dataSource"
users-by-username-query=
"select username,password, enabled from users where username=?"
authorities-by-username-query=
"select username, role from user_roles where username =? " />
</ss:authentication-provider>
</ss:authentication-manager>
</spring:beans>
<mule-ss:security-manager>
<mule-ss:delegate-security-provider name="jdbc-provider" delegate-ref="authenticationManager" />
</mule-ss:security-manager>
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration" />
<flow name="SpringExample">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<logger level="INFO" message="## received" doc:name="Logger"/>
<http:basic-security-filter realm="mule-realm" securityProviders="jdbc-provider"/>
<logger level="INFO" message="## passed security" doc:name="Logger"/>
</flow>
</mule>
堆栈追踪:
INFO 2015-03-27 21:31:04,255 [[spring-security-maven].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: ## received
ERROR 2015-03-27 21:31:04,299 [[spring-security-maven].HTTP_Listener_Configuration.worker.01] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Authentication Attempt Failed. Message payload is of type: NullPayload
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. No suitable driver found for jdbc:mysql://localhost:3306/test (java.sql.SQLException)
java.sql.DriverManager:596 (null)
2. Could not get JDBC Connection; nested exception is java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test (org.springframework.jdbc.CannotGetJdbcConnectionException)
org.springframework.jdbc.datasource.DataSourceUtils:80 (null)
3. Could not get JDBC Connection; nested exception is java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test (org.springframework.security.authentication.AuthenticationServiceException)
org.springframework.security.authentication.dao.DaoAuthenticationProvider:85 (null)
4. Authentication Attempt Failed. Message payload is of type: NullPayload (org.mule.api.security.UnauthorisedException)
org.mule.security.MuleSecurityManager:91 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/security/UnauthorisedException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test
at java.sql.DriverManager.getConnection(DriverManager.java:596)
at java.sql.DriverManager.getConnection(DriverManager.java:187)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:173)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
答案 0 :(得分:2)
这是一个骡子问题。将jar添加到
<MULE_PATH>/mule-standalone-3.x.0/lib/mule
和
<MULE_STUDIO_PATH>/AnypointStudio/plugins/org.mule.tooling.server.3.x.xxxx/mule/lib/mule
答案 1 :(得分:0)
默认情况下,mole不为各自的DB连接提供jdbc驱动程序。我们需要明确地将jar添加到项目开发的类路径中。