【发布时间】:2014-05-20 15:48:14
【问题描述】:
我是 WebLogic 新手,对 Hibernate / Spring 应用程序还很陌生,因为我的主要语言是 C#,而我的主要服务器一直是 Windows 服务器,所以请原谅我可能遇到的任何简单错误。
我无法部署到我们的 WebLogic 10.3.4 服务器。它在我的 WebLogic 实例上本地工作,但不在远程服务器上。
我将 Hibernate 4.2.8 用于持久性,并将 Spring MVC 4.0 用于我的 Web 应用程序框架。我收到的错误是:
Failed to load webapp: 'ncms2_May20.war'
Message icon - Error Substituted for missing class Exception [EclipseLink-28010] (Eclipse Persistence Services - 2.1.2.v20101206-r8635) - org.eclipse.persistence.exceptions.EntityManagerSetupException Exception Description: PersistenceUnitInfo ncms2 has transactionType JTA, but does not have a jtaDataSource defined.
我正在使用基于 Spring 注释的 Hibernate 配置文件。
package mil.navy.navsupbsc.utilities;
import java.util.Properties;
import javax.sql.DataSource;
import com.app.AuditInterceptor;
import org.hibernate.SessionFactory;
import org.hibernate.dialect.Oracle10gDialect;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.hibernate4.HibernateTransactionManager;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
@Configuration
public class HibernateConfiguration {
@Value("#{dataSource}")
private DataSource dataSource;
@Bean
public LocalSessionFactoryBean sessionFactoryBean() {
Properties props = new Properties();
props.put("hibernate.dialect", Oracle10gDialect.class.getName());
props.put("hibernate.format_sql", "true");
props.put("hibernate.hbm2ddl.auto", "update");
props.put("hibernate.show_sql", "true");
props.put("hibernate.format_sql", "true");
props.put("hibernate.use_sql_comments", "true");
LocalSessionFactoryBean bean = new LocalSessionFactoryBean();
bean.setEntityInterceptor(new AuditInterceptor());
bean.setPackagesToScan(new String[] { "com.app.entity" });
bean.setHibernateProperties(props);
bean.setDataSource(this.dataSource);
return bean;
}
@Bean
public HibernateTransactionManager transactionManager() {
return new HibernateTransactionManager(sessionFactoryBean().getObject());
}
}
我的 Spring Servlet 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:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util" xmlns:c="http://www.springframework.org/schema/c"
xmlns:cache="http://www.springframework.org/schema/cache" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:task="http://www.springframework.org/schema/task" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.databaseurl}"
p:username="${jdbc.username}" p:password="${jdbc.password}" />
<mvc:annotation-driven />
<tx:annotation-driven transaction-manager="transactionManager" />
<mvc:resources mapping="/resources/**" location="/resources/" />
<context:component-scan base-package="com.app" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass">
<value>
org.springframework.web.servlet.view.tiles2.TilesView
</value>
</property>
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
</beans>
你们中的任何人都可以帮助我完成这项工作吗?我感谢任何和所有的帮助。谢谢!
更新
我做了以下切换到 JTA:
- 在 Hibernate java 配置文件中添加了 JtaTransactionManager,而不是使用 HibernateTransactionManager。
- 在 LocalSessionFactoryBean 中设置 JtaTransactionManager 属性
- 在 spring-servlet 文件中添加了 jdni 查找
- 在 web.xml 和 weblogic.xml 文件中添加了资源引用
- 删除了 spring-servlet 中的数据源,并删除了 hibernate java 配置文件中对它的引用
- 在服务器上创建了一个数据源
但仍然不能 100% 工作。将保持更新。
更新:这是我一直在使用的有用资源 (http://spring.io/blog/2011/08/15/configuring-spring-and-jta-without-full-java-ee/)
【问题讨论】:
-
如果您使用的是 Hibernate,为什么您的错误消息是指 eclipse 链接?
-
我不知道 - 虽然我知道 EclipseLink 已安装在服务器上,但我并没有在应用程序中的任何内容中提及 EclipseLink。
-
这就是为什么我真的很困惑。由于我没有使用它,我不知道在应用程序中要更改什么......可能是服务器配置问题?
标签: java spring hibernate jpa transactions