[英]Configuring hibernate 4.2.1 in a maven project
I'm configuring Hibernate 4.2.1 in a maven project and I'm using MS SQL JDBC to connect to a SQL Server Database. 我正在Maven项目中配置Hibernate 4.2.1,并且正在使用MS SQL JDBC连接到SQL Server数据库。 When I run my class Test I get the following error: 当我运行类Test时,出现以下错误:
WARN : org.hibernate.internal.util.xml.DTDEntityResolver - HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
Exception in thread "main" org.hibernate.service.classloading.spi.ClassLoadingException: Specified JDBC Driver com.microsoft.sqlserver.jdbc.SQLServerDriver could not be loaded
at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:111)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:223)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:89)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:78)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2293)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2289)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1758)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1798)
at com.lbv.test.Test.main(Test.java:12)
Caused by: org.hibernate.service.classloading.spi.ClassLoadingException: Unable to load class [com.microsoft.sqlserver.jdbc.SQLServerDriver]
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:149)
at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:106)
... 14 more
Caused by: java.lang.ClassNotFoundException: Could not load requested class : com.microsoft.sqlserver.jdbc.SQLServerDriver
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader.findClass(ClassLoaderServiceImpl.java:296)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:146)
... 15 more
I need your help friends. 我需要你的帮助朋友。
You need to remove <scope>test</scope>
from your dependency declaration. 您需要从依赖项声明中删除<scope>test</scope>
。 You aren't only using the driver for your tests, but also for your actual runtime use. 您不仅将驱动程序用于测试,而且还用于实际运行时。
Specifying <scope>test</scope>
will instruct Maven to only load the dependency when running your tests. 指定<scope>test</scope>
将指示Maven仅在运行测试时加载依赖项。 You should also ask yourself if you really want to use a preview version, and not a officially released version (ie: 6.2.2.jre8). 您还应该问自己是否真的要使用预览版本,而不是正式发布的版本(即6.2.2.jre8)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.