将spring3+hibernate J2EE应用程序部署到JBoss 6时找不到jndi数据源

发布于 2024-10-07 12:21:41 字数 1833 浏览 2 评论 0原文

我有一个使用 Spring 3.0 + 最新版本的 Hibernate (3.6) 的 J2EE 应用程序,我想将其部署在 JBoss 6 CR1 上。

但我遇到了一个异常,指出在部署应用程序时找不到数据源。

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [javax.sql.DataSource] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:920) [:3.0.5.RELEASE]
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:789) [:3.0.5.RELEASE]
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703) [:3.0.5.RELEASE]
 at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795) [:3.0.5.RELEASE]
 at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723) [:3.0.5.RELEASE]
 ... 159 more

我检查了JBoss应用服务器的JMX控制台,我在Spring中声明的数据源位于java命名空间下。

我在 application-context.xml 中将数据源定义为

<jee:jndi-lookup id="dataSource" jndi-name="java:ThisIsMyDataSource"/>

在 persistence.xml 文件中声明:

<persistence-unit name="persistenceUnit" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>java:/ThisIsMyDataSource</jta-data-source>
</persistence-unit>

名称为 ThisIsMyDataSource 的数据源位于 /jboss/server/default/deploy 的部署文件夹中

看起来我的应用程序正在尝试查找javax.sql.datasource 的 bean 自动装配到其他一些类的构造函数中,但失败了。

有谁知道如何解决这个问题?

I have a J2EE application which uses Spring 3.0 + latest version of Hibernate (3.6) and I want to deploy it on JBoss 6 CR1.

But I came across an exception stating that the datasource is not found when I deployed the application.

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [javax.sql.DataSource] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:920) [:3.0.5.RELEASE]
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:789) [:3.0.5.RELEASE]
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703) [:3.0.5.RELEASE]
 at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795) [:3.0.5.RELEASE]
 at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723) [:3.0.5.RELEASE]
 ... 159 more

I have checked the JMX console of JBoss Application Server and the datasource I declared in Spring is under java namespace.

I delcared the datasource in my application-context.xml as

<jee:jndi-lookup id="dataSource" jndi-name="java:ThisIsMyDataSource"/>

In persistence.xml file I declared:

<persistence-unit name="persistenceUnit" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>java:/ThisIsMyDataSource</jta-data-source>
</persistence-unit>

A datasource with a name called ThisIsMyDataSource is in the deploy folder of /jboss/server/default/deploy

It looks like my application was trying to look for the bean for javax.sql.datasource to autowire into some other classes' constructors and failed.

Does anyone know how to resolve this?

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

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

发布评论

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

评论(1

当爱已成负担 2024-10-14 12:21:41

这似乎是一个错字。你可以尝试用

<jee:jndi-lookup id="dataSource" jndi-name="java:/ThisIsMyDataSource"/>

而不是

<jee:jndi-lookup id="dataSource" jndi-name="java:ThisIsMyDataSource"/>

It seems like a typo. Can you try with

<jee:jndi-lookup id="dataSource" jndi-name="java:/ThisIsMyDataSource"/>

instead of

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