我遵循了一些教程,以便使用spring,hibernate模式在tomcat上运行来设置Web应用程序。
尝试运行我的应用程序时,出现错误“未设置’hibernate.dialect’时连接不能为空”
我的hibernate.cfg.xml是
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC"-//Hibernate/Hibernate ConfigurationDTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/myproject</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<mapping class="com.myproject.entity.user.UserEntity"></mapping>
<mapping class="com.myproject.entity.user.UserAboutEntity"></mapping>
<mapping class="com.myproject.entity.user.UserBasicInfoEntity"></mapping>
<mapping class="com.myproject.entity.user.UserDescriptionEntity"></mapping>
<mapping class="com.myproject.entity.user.UserInterestsEntity"></mapping>
<mapping class="com.myproject.entity.user.UserEntity"></mapping>
<mapping class="com.myproject.entity.user.UserPersonalViewsEntity"></mapping>
<mapping class="com.myproject.entity.user.UserPetsEntity"></mapping>
<mapping class="com.myproject.entity.user.UserSportsEntity"></mapping>
<mapping class="com.myproject.entity.user.PartnerAboutEntity"></mapping>
<mapping class="com.myproject.entity.user.PartnerBasicInfoEntity"></mapping>
<mapping class="com.myproject.entity.user.PartnerDescriptionEntity"></mapping>
<mapping class="com.myproject.entity.user.PartnerInterestsEntity"></mapping>
<mapping class="com.myproject.entity.user.PartnerPersonalViewsEntity"></mapping>
<mapping class="com.myproject.entity.user.PartnerPetsEntity"></mapping>
<mapping class="com.myproject.entity.user.PartnerSportsEntity"></mapping>
<mapping class="com.myproject.entity.user.PartnerStyleEntity"></mapping>
<mapping class="com.myproject.entity.user.MessagePageEntity"></mapping>
<mapping class="com.myproject.entity.user.MessageEntity"></mapping>
<mapping class="com.myproject.entity.user.MatchListEntity"></mapping>
</session-factory>
</hibernate-configuration>
我的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myproject.controller</groupId>
<artifactId>myproject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>myproject Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<spring.version>3.1.1.RELEASE</spring.version>
</properties>
<build>
<finalName>myproject-webapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>net.leadware</groupId>
<artifactId>hibernate4-maven-plugin</artifactId>
<version>1.0.1</version>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>repository.jboss.org-public</id>
<name>JBoss repository</name>
<url>https://repository.jboss.org/nexus/content/groups/public</url>
</repository>
</repositories>
<dependencies>
<!-- Spring dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc-portlet</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- MySQL database driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.30</version>
</dependency>
<!-- Hibernate framework -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.2.7.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.7.Final</version>
</dependency>
<!-- Hibernate library dependecy start -->
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.7</version>
</dependency>
<!-- Hibernate library dependecy end -->
<!-- Tomcat -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp</artifactId>
<version>7.0.52</version>
</dependency>
<!-- Log4J -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
</project>
user-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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<context:annotation-config />
<context:component-scan base-package="com.findlove.controller" />
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value="/WEB-INF/view/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages"></property>
<property name="defaultEncoding" value="UTF-8"></property>
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties"></bean>
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"
p:password="${jdbc.password}"></bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="packagesToScan" value="com.findlove.entity" />
</bean>
<bean id="userDAO" class="com.findlove.dao.user.UserDAOImpl"></bean>
<bean id="userManager" class="com.findlove.service.user.UserManagerImpl"></bean>
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
关于为什么我会收到此错误的任何建议将不胜感激。
丽莎
您提到的教程中的一段代码:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
这是指定hibernate.cfg.xml的地方,也是放置方言的地方。如果您有<property name="dataSource" ref="dataSource" />
会话工厂,则在hibernate.cfg.xml中不需要它。我建议再次查看该教程的源代码并相应地调整您的代码。
问题内容: 我正在尝试运行一个通过spring-jpa使用hibernate模式的spring-boot应用程序,但出现此错误: 我的文件是这样的: 我的hibernate配置是(方言配置位于此类的最后一个方法中): 我在这里做错了什么? 问题答案: 首先删除所有配置,Spring Boot会为你启动它。如果你确实需要a 而不是。 确保你的类路径中有一个,然后添加以下属性。 如果你确实需要访问,并
使用Spring3设置hibernate有更多问题。这一次是说连接是nul,因为没有设置方言,它在我的hibernate.cfg.xml文件上。
我见过几个类似的问题,不幸的是没有一个答案解决了我的问题。我正在尝试构建一个运行Hibernate的web应用程序,并得到以下异常: 下面是hibernate.cfg.xml文件:
问题内容: 我正在使用Hibernate最新版本。 我的文件内容: 创建SessionFactory的实用程序类: 在我的方法中使用它时,出现以下异常: 我尝试了很多选择,并寻找了在线资源,hibernate文档,但找不到此处缺少的内容。任何帮助表示赞赏。 问题答案: 最终能够解决问题,问题在于创建方法。 首先,正式文件是第一个要去的地方,我必须说,Hibernate正式文件似乎没有更新为最新版本
我有一个Spring Boot JPA应用程序。每当我尝试运行它时,它都会失败: 我已经在这里查看了相关问题,但大多数问题似乎与数据库尚未启动、凭据不正确等问题有关。但是,我能够很好地连接到PSQL客户端,所以这不是问题所在。我已经尝试过使用和不使用application.properties中指定的平台和驱动程序: 此外,在错误之上,应用程序实际上打印出以下内容: 问题可能是什么?这个应用程序实
我知道这是一个常见的问题,但没有一个解决方案适合我。下面是我的胸带。xml: 当应用程序运行时,我得到以下异常: 如果我添加