gpt4 book ai didi

postgresql - Spring MVC + Maven + JBoss : can't deploy (The application must supply JDBC connections)

转载 作者:行者123 更新时间:2023-11-29 14:04:22 25 4
gpt4 key购买 nike

我目前正在尝试使用 Maven 设置一个 Spring MVC 3.1.1 项目并在 JBoss 7.1.1 上进行部署。我已经尝试了几个教程,但我无法完成任何一个,因为在某些时候我会被教程中假定的但在我的设置中不存在的东西卡住。

我的第二次尝试是使用 eclipse 创建一个“Spring MVC 项目”,并将配置文件从一个工作的 Spring MVC 项目复制/粘贴到我的新项目,但到目前为止效果不佳。

我使用 JPA 创建了我的整个域,现在我尝试部署时出现此异常:Schema export unsuccessful: java.lang.UnsupportedOperationException: The application must supply JDBC connections.

我发现许多论坛帖子等都有同样的问题,但没有一个建议的解决方案适合我的问题。 Postgresql 驱动程序在 Maven 依赖项中定义明确,并且在构建路径中。

这是 main/src/resources/META-INF/persistence.xml 文件:

<persistence-unit name="root">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.macoloc.domain.Colocation</class>
<class>com.macoloc.domain.Invitation</class>
<class>com.macoloc.domain.Key</class>
<class>com.macoloc.domain.Message</class>
<class>com.macoloc.domain.MessageSeenBy</class>
<class>com.macoloc.domain.Payment</class>
<class>com.macoloc.domain.PaymentParticipation</class>
<class>com.macoloc.domain.Ping</class>
<class>com.macoloc.domain.Subtask</class>
<class>com.macoloc.domain.Task</class>
<class>com.macoloc.domain.TaskOrder</class>
<class>com.macoloc.domain.User</class>
<class>com.macoloc.domain.Versionable</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="create" />
</properties>
</persistence-unit>

这是 src/main/webapp/WEB-INF/web.xml 文件:

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml,/WEB-INF/spring/infrastructure/infrastructure.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

这是 src/main/resources/WEB-INF/spring/appServlet/servlet-context.xml 文件的一部分:

<context:component-scan base-package="com.macoloc" />

<annotation-driven />

<tx:annotation-driven />

<mvc:annotation-driven />

<mvc:resources mapping="/js/**" location="/resources/js/" />
<mvc:resources mapping="/css/**" location="/resources/css/" />

<resources mapping="/resources/**" location="/resources/" />

<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>

最后是 src/main/resources/WEB-INF/spring/infrastructure/infrastructure.xml 文件:

<context:annotation-config />

<tx:annotation-driven />

<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSourceDirect" />
</bean>

<bean id="dataSourceDirect" class="org.postgresql.ds.PGSimpleDataSource">
<property name="user" value="macoloc"></property>
<property name="password" value="macoloc"></property>
<property name="portNumber" value="5432"></property>
<property name="serverName" value="localhost"></property>
<property name="databaseName" value="MaColoc"></property>
</bean>

<bean class="org.springframework.orm.jpa.JpaTransactionManager"
id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

在 postgres 中,我将用户“macoloc”设置为使用数据库“MaColoc”的“macoloc”模式。

请注意,我正在使用所有这些配置文件的项目不是我设置的(显然因为这个正在运行......)。可能有一些文件未使用?我不知道。我对此很陌生。

知道哪里出了问题吗?你们需要更多文件吗?

谢谢!

编辑:这里是堆栈跟踪:

16:11:21,568 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-8) JBAS010404: Deploying non-JDBC-compliant driver class org.postgresql.Driver (version 9.0)
16:11:21,585 INFO [org.jboss.as.jpa] (MSC service thread 1-4) JBAS011402: Starting Persistence Unit Service 'MaColoc.war#root'
16:11:22,205 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-4) HHH000231: Schema export unsuccessful: java.lang.UnsupportedOperationException: The application must supply JDBC connections
at org.hibernate.service.jdbc.connections.internal.UserSuppliedConnectionProviderImpl.getConnection(UserSuppliedConnectionProviderImpl.java:62) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:51) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.tool.hbm2ddl.DatabaseExporter.<init>(DatabaseExporter.java:52) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:368) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:305) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:294) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:452) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:84) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_21]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_21]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_21]

而且:最奇怪的是,我注意到这些表是在我的数据库中创建的……什么?

最佳答案

您将 JPA 配置为由 Spring 初始化(使用 LocalContainerEntityManagerFactoryBean),但 JBoss 也会看到您的 persistence.xml 并尝试自行初始化 JPA(根据应用程序服务器环境的 JPA 规范)。显然,它失败了,因为您没有在 persistence.xml 中配置数据源。

为避免此问题,Spring 允许您为 persistence.xml 使用不同的名称:

<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
...
<property name = "persistenceXmlLocation"
value = "classpath:/META-INF/spring-persistence.xml" />
</bean>

或者,从 Spring 3.1 开始,您可以完全不使用 persistence.xml 配置 JPA。

另请参阅:

关于postgresql - Spring MVC + Maven + JBoss : can't deploy (The application must supply JDBC connections),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17345500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com