无法创建类“”的 JDBC 驱动程序对于连接 URL 'null

发布于 2024-10-04 16:46:52 字数 4098 浏览 1 评论 0原文

我正在尝试在 Tomcat 5.5 中使用 Atomkios 配置 JTA 事务以获得 jndi 支持 我正在使用 spring、jpa+hybernate 当我尝试访问我的数据库时,我收到这样的错误:

org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
 org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:82)
 org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:572)
 org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:636)
 org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:665)
 org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:673)
 org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:713)
 com.evolvus.springsecurity.impl.CustomJdbcDaoImpl.loadUsersByUsername(CustomJdbcDaoImpl.java:78)
 org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl.loadUserByUsername(JdbcDaoImpl.java:152)
 com.evolvus.springsecurity.impl.UsernamePasswordAuthenticationProvider.authenticate(UsernamePasswordAuthenticationProvider.java:27)
 org.springframework.security.authentication.ProviderManager.doAuthentication(ProviderManager.java:120)
 org.springframework.security.authentication.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:48)
 com.evolvus.springsecurity.impl.LoginAuthenticationFilter.attemptAuthentication(LoginAuthenticationFilter.java:38)
 org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
 org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
 org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
 org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:109)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
 org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:149)
 org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
 org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
 org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

我的 config.xml

<beans: bean id="dataSource"
  class="org.springframework.jndi.JndiObjectFactoryBean" >
  <beans: property name="jndiName">
   <beans:value>java:comp/env/jdbc/welcome</beans:value>
  </beans: property>   
 </beans: bean>
and i configure data source in tomcat5.5/config/context.xml       


   <Resource name="jdbc/welcome"  
     auth="Container" 
     type="com.atomikos.jdbc.AtomikosDataSourceBean" 
     factory="com.atomikos.tomcat.BeanFactory"
     uniqueResourceName="jdbc/myDB"
     xaDataSourceClassName="org.apache.derby.jdbc.EmbeddedXADataSource"
     maxPoolSize="3"
     minPoolSize="1"
     xaProperties.databaseName="payhub"
     xaProperties.url="jdbc\:mysql\://devserver\:3306/payhub" 
     />            

和我的应用程序 web.xml 中

<resource-ref>
   <description>PaymentsDatabase</description>
   <res-ref-name>jdbc/welcome</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
   <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

我在这里犯了什么错误?

I am trying to configure JTA Transactions with Atomkios in Tomcat 5.5 for jndi support
I am using spring,jpa+hybernate
when i m trying to access my database, i am getting the error like this

org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
 org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:82)
 org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:572)
 org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:636)
 org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:665)
 org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:673)
 org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:713)
 com.evolvus.springsecurity.impl.CustomJdbcDaoImpl.loadUsersByUsername(CustomJdbcDaoImpl.java:78)
 org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl.loadUserByUsername(JdbcDaoImpl.java:152)
 com.evolvus.springsecurity.impl.UsernamePasswordAuthenticationProvider.authenticate(UsernamePasswordAuthenticationProvider.java:27)
 org.springframework.security.authentication.ProviderManager.doAuthentication(ProviderManager.java:120)
 org.springframework.security.authentication.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:48)
 com.evolvus.springsecurity.impl.LoginAuthenticationFilter.attemptAuthentication(LoginAuthenticationFilter.java:38)
 org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
 org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
 org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
 org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:109)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
 org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:149)
 org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
 org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
 org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

my config.xml

<beans: bean id="dataSource"
  class="org.springframework.jndi.JndiObjectFactoryBean" >
  <beans: property name="jndiName">
   <beans:value>java:comp/env/jdbc/welcome</beans:value>
  </beans: property>   
 </beans: bean>
and i configure data source in tomcat5.5/config/context.xml       


   <Resource name="jdbc/welcome"  
     auth="Container" 
     type="com.atomikos.jdbc.AtomikosDataSourceBean" 
     factory="com.atomikos.tomcat.BeanFactory"
     uniqueResourceName="jdbc/myDB"
     xaDataSourceClassName="org.apache.derby.jdbc.EmbeddedXADataSource"
     maxPoolSize="3"
     minPoolSize="1"
     xaProperties.databaseName="payhub"
     xaProperties.url="jdbc\:mysql\://devserver\:3306/payhub" 
     />            

and in my application web.xml is

<resource-ref>
   <description>PaymentsDatabase</description>
   <res-ref-name>jdbc/welcome</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
   <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

what mistake i have done here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多彩岁月 2024-10-11 16:46:52

必须指定您的上下文,例如:

META-INF/context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context>
  <Resource
    name="jdbc/database"
    auth="Container"
    type="javax.sql.DataSource"
    maxActive="4"
    maxIdle="2"
    username="root"
    maxWait="5000"
    driverClassName="com.mysql.jdbc.Driver"
    password="password"
    url="jdbc:mysql://localhost:3306/database_name"/>
</Context>

WEB-INF/web.xml

<web-app>
...
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/classes/app-context.xml</param-value>
    </context-param>
...
    <resource-ref>
        <description>DB Connection</description>
        <res-ref-name>jdbc/database</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
</web-app>

app-context.xml

...
<jee:jndi-lookup id="dataSourcejndi" jndi-name="jdbc/database"
        lookup-on-startup="false" proxy-interface="javax.sql.DataSource"
        cache="true" resource-ref="true" />
...
<beans: bean id="dataSource"
  class="org.springframework.jndi.JndiObjectFactoryBean" lazy-init="true">
  <property name="dataSource" ref="dataSourcejndi" /> 
 </beans: bean>
...

希望帮助...

Must specify your Context like: for example:

META-INF/context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context>
  <Resource
    name="jdbc/database"
    auth="Container"
    type="javax.sql.DataSource"
    maxActive="4"
    maxIdle="2"
    username="root"
    maxWait="5000"
    driverClassName="com.mysql.jdbc.Driver"
    password="password"
    url="jdbc:mysql://localhost:3306/database_name"/>
</Context>

WEB-INF/web.xml

<web-app>
...
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/classes/app-context.xml</param-value>
    </context-param>
...
    <resource-ref>
        <description>DB Connection</description>
        <res-ref-name>jdbc/database</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
</web-app>

app-context.xml

...
<jee:jndi-lookup id="dataSourcejndi" jndi-name="jdbc/database"
        lookup-on-startup="false" proxy-interface="javax.sql.DataSource"
        cache="true" resource-ref="true" />
...
<beans: bean id="dataSource"
  class="org.springframework.jndi.JndiObjectFactoryBean" lazy-init="true">
  <property name="dataSource" ref="dataSourcejndi" /> 
 </beans: bean>
...

Hope helps...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文