使用服务器的PostgreSQL数据库

时间:2014-02-03 12:44:15

标签: spring postgresql pgadmin

我正在使用eclipse kepler和PostgreSQL,我想将我的项目连接到服务器的PostgreSQL数据库,所以我从<jdbc.url>jdbc:postgresql://localhost:5433/${db.name}</jdbc.url>更改了我的网址 到<jdbc.url>jdbc:postgresql://192.168.1.1:5433/${db.name}</jdbc.url> 但现在它开始给我错误

{  SEVERE:将上下文初始化事件发送到类org.springframework.web.context.ContextLoaderListener的侦听器实例的异常 org.springframework.beans.factory.BeanCreationException:使用名称&#39; org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0&#39;创建bean时出错:bean的初始化失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为&#39; entityManagerFactory&#39;的bean时出错。在URL [file:/ E:/Java%20Project/DTSAdminPortal/common/target/classes/jpa.xml]中定义:init方法的调用失败;嵌套异常是javax.persistence.PersistenceException:[PersistenceUnit:hibernatePersistenceUnit]无法构建EntityManagerFactory     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)     在org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:294)     在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)     在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)     在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)     在org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:733)     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454)     在org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)     在org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)     在org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)     在org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)     在org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)     在org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)     在org.apache.catalina.core.StandardHost.start(StandardHost.java:785)     在org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)     在org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)     在org.apache.catalina.startup.Embedded.start(Embedded.java:825)     在org.codehaus.mojo.tomcat.AbstractRunMojo.startContainer(AbstractRunMojo.java:558)     在org.codehaus.mojo.tomcat.AbstractRunMojo.execute(AbstractRunMojo.java:255)     在org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)     在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)     在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)     在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)     在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)     在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)     在org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)     在org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)     在org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)     在org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)     在org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)     在org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)     在org.apache.maven.cli.MavenCli.main(MavenCli.java:158)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)     at java.lang.reflect.Method.invoke(Unknown Source)     在org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)     在org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)     在org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)     在org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) } { 引起:org.springframework.beans.factory.BeanCreationException:创建名称为&#39; entityManagerFactory&#39;的bean时出错在URL [file:/ E:/Java%20Project/DTSAdminPortal/common/target/classes/jpa.xml]中定义:init方法的调用失败;嵌套异常是javax.persistence.PersistenceException:[PersistenceUnit:hibernatePersistenceUnit]无法构建EntityManagerFactory     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)     在org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:294)     在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)     在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)     在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)     at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:424)     在org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:277)     at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.detectPersistenceExceptionTranslators(PersistenceExceptionTranslationInterceptor.java:139)     在org.springframework.dao.support.PersistenceExceptionTranslationInterceptor。(PersistenceExceptionTranslationInterceptor.java:79)     在org.springframework.dao.annotation.PersistenceExceptionTranslationAdvisor。(PersistenceExceptionTranslationAdvisor.java:70)     at org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor.setBeanFactory(PersistenceExceptionTranslationPostProcessor.java:103)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1475)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1443)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)     ... 40多} {

引起:javax.persistence.PersistenceException:[PersistenceUnit:hibernatePersistenceUnit]无法构建EntityManagerFactory     在org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)     在org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)     在org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:268)     在org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)     ......还有55个 } {引起:org.hibernate.HibernateException:&#39; hibernate.dialect&#39;必须在没有可用连接时设置     在org.hibernate.dialect.resolver.DialectFactory.buildDialect(DialectFactory.java:106)     在org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:148)     在org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2836)     在org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2832)     在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)     在org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:906)     ... 60多}}

2014年2月4日下午2:21:01 org.apache.catalina.core.StandardContext start 严重:错误listenerStart

请帮我做什么,以便我可以访问我服务器的数据库

1 个答案:

答案 0 :(得分:0)

首先,您需要获得一些网络基础知识。测试数据库服务器是否可访问且没有防火墙阻止它(例如:使用telnet)。

然后,如果你向下看你的异常跟踪,它抱怨缺少hibernate.dialect。通常,这在META-INF / persistence.xml上设置如下:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">
   <persistence-unit name="sample">
      ..
      <properties>
         <property name="hibernate.dialect" value= "org.hibernate.dialect.PostgreSQLDialect"/>
         ...
      </properties>
   </persistence-unit>
</persistence>