简体   繁体   English

我无法在 Windows 上运行 Spring Boot jar

[英]I can't run a spring boot jar on windows

I started working on a projet, and i'm using windows.我开始在一个项目上工作,我正在使用 Windows。 Basically i could generate a Jar file using maven, but when i try to run my Jar file it doesn't work well.基本上我可以使用 maven 生成一个 Jar 文件,但是当我尝试运行我的 Jar 文件时它不能正常工作。 Sounds like it doesn't find hibernate properties.听起来它没有找到休眠属性。

My error:我的错误:

2017-01-15 16:03:12.454  INFO 19012 --- [main] org.hibernate.Version                    : 
    HHH000412: Hibernate Core    {5.0.11.Final} 
2017-01-15 16:03:12.473  INFO 19012 --- [main] org.hibernate.cfg.Environment            : 
    HHH000206: hibernate.properties not found 
2017-01-15 16:03:12.480  INFO 19012 --- [main] org.hibernate.cfg.Environment            : 
    HHH000021: Bytecode provider name : javassist 
2017-01-15 16:03:13.122  INFO 19012 --- [main] o.hibernate.annotations.common.Version   : 
    HCANN000001: Hibernate Commons Annotations {5.0.1.Final} 
2017-01-15 16:03:16.112  WARN 19012 --- [main] o.h.e.j.e.i.JdbcEnvironmentInitiator     : 
    HHH000342: Could not obtain connection to query metadata : Access denied for user root 'root'@'localhost' (using password: YES) 
2017-01-15 16:03:16.135  WARN 19012 --- [main] ationConfigEmbeddedWebApplicationContext : 
    Exception encountered during context initialization - cancelling refresh attempt: 
        org.springframework.beans.factory.BeanCreationException: 
            Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: 
                Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: 
                    Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] 
2017-01-15 16:03:16.149  INFO 19012 --- [main] o.apache.catalina.core.StandardService   : 
    Stopping service Tomcat    
2017-01-15 16:03:16.234  WARN 19012 --- [main] o.s.boot.SpringApplication               : 
    Error handling failed (Error creating bean with name 'delegatingApplicationListener' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]:    
        BeanPostProcessor before instantiation of bean  failed; nested exception is org.springframework.beans.factory.BeanCreationException: 
            Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': 
                Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 
                    No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' is defined)
2017-01-15 16:03:16.275 ERROR 19012 --- [main] o.s.boot.SpringApplication               : 
    Application startup failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: 
        Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: 
            Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583) ~[spring-beans-4.3.3.RELEASE.jar !/:4.3.3.RELEASE]
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.3.3.RELEASE.jar!/:    4.3.3.RELEASE]
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
                at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
                at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
                at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
                at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
                at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1076) ~[spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
                at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:851) ~[spring-context-4.3.3.RELEASE.jar!/:4 .3.3.RELEASE]
                at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
                at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
                at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
                at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
                at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
                at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
                at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
                at com.SimonSaysApplication.main(SimonSaysApplication.java:32) [classes!/:0.0.1-SNAPSHOT]
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_77]
                at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_77]
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_77]
                at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_77]
                at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [simonsays-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
                at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [simonsays-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
                at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [simonsays-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
                at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58) [simonsays-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] 
            Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
                at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:264) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
                at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:228) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
                at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:207) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
                at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
                at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
                at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
                at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:207) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
                at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
                at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
                at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:847) ~[hibernate-entitymanager-5.0.11.Final.jar!/:5.0.11.Fin al]
                at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:874) ~[hibernate-entitymanager-5.0.11.Final.jar!/:5.0.11.Final]
                at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4 .3.3.RELEASE.jar!/:4.3.3.RELEASE]
                at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) ~[spring-orm-4.3.3.RE LEASE.jar!/:4.3.3.RELEASE]
                at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373) ~[spring-orm-4.3.3.RELEASE.jar!/:4 .3.3.RELEASE]
                at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362) ~[spring-orm-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642) ~[spring-beans-4.3.3.RELEASE. jar!/:4.3.3.RELEASE]
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579) ~[spring-beans-4.3.3.RELEASE.jar !/:4.3.3.RELEASE]            
                ... 24 common frames omitted 
            Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
                at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
                at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
                at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
                at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
                at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
                at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:254) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]            
                ... 40 common frames omitted

My hibernate config is located on \\src\\main\\resources\\application.properties我的休眠配置位于 \\src\\main\\resources\\application.properties

db.driver = com.mysql.jdbc.Driver
db.url = jdbc:mysql://localhost:3306/simonsays?characterEncoding=UTF-8&useSSL=false
db.username = root
db.password = 1234

#Hibernate configuration
hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
hibernate.show_sql = false
hibernate.hbm2ddl.auto = update
entitymanager.packagesToScan = com

How can i handle it?我该如何处理?

[UPDATE] [更新]

I could get a different result when running using mvn spring-boot:run使用 mvn spring-boot:run 运行时可能会得到不同的结果

  • Instead of the old error, i could see my database but i'm getting a weird error when it's turning up the tomcat:我可以看到我的数据库,而不是旧的错误,但是当它打开 tomcat 时出现了一个奇怪的错误:

    Description:描述:

    The Tomcat connector configured to listen on port 444 failed to start.配置为侦听端口 444 的 Tomcat 连接器无法启动。 The port may already be in use or the connector may be misconfigured.端口可能已在使用中,或者连接器可能配置错误。

    Action:行动:

    Verify the connector's configuration, identify and stop any process that's listening on port 444, or configure this application to listen on another port.验证连接器的配置,识别并停止侦听端口 444 的任何进程,或将此应用程序配置为侦听另一个端口。

Looks like your DB is rejecting the connection as per error Access denied for use r 'root'@'localhost' (using password: YES) .看起来您的数据库正在根据错误Access denied for use r 'root'@'localhost' (using password: YES)拒绝连接。 Can you try to login using MySQL CLI or MySQL Workbench to your database using the same credentials as in application.properties?您可以尝试使用与 application.properties 中相同的凭据使用 MySQL CLI 或 MySQL Workbench 登录到您的数据库吗?

Your log says db is refusing connection :您的日志显示 db 拒绝连接:

  HHH000342: Could not obtain connection to query metadata : 
Access denied for user root 'root'@'localhost' (using password: YES) 

so please try to hit DB with the credential that you have provided in your application and if its correct then please bind it with 127.0.0.1 or the IP of your local system instead of localhost as said by Alex Roig.因此,请尝试使用您在应用程序中提供的凭据访问 DB,如果正确,请将其绑定到 127.0.0.1 或本地系统的 IP,而不是 Alex Roig 所说的 localhost。

Ok, i think i got the problem solved:好的,我想我解决了问题:

first, i was trying to build a jar to run after, it wasn't working well because wasn't loading my configurations, then i got a better result using:首先,我试图构建一个 jar 来运行,它运行不佳,因为没有加载我的配置,然后我使用以下方法获得了更好的结果:

mvn spring-boot:run

But i got a tomcat error because the SSL, then i just had to disable SSL and change port to 8080 as usual and it's running但是我因为 SSL 出现了一个 tomcat 错误,然后我只需要像往常一样禁用 SSL 并将端口更改为 8080 并且它正在运行

Properties you have mentioned in application.properties file are not understood by spring-boot. spring-boot 无法理解您在 application.properties 文件中提到的属性。 Use the following properties to assign database details使用以下属性分配数据库详细信息

spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/simonsays?characterEncoding=UTF-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=1234
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM