Spring boot 如何在没有STS的情况下启动jar文件

Spring boot 如何在没有STS的情况下启动jar文件,spring-boot,Spring Boot,我尝试执行java-jar jarname.jar,但出现了一个错误 然而,如果我在STS上启动该项目,我不会从以前得到错误 我不明白为什么它不工作,为什么STS工作,而jar也不工作 SLF4J: Found binding in [jar:file:/C:/Users/YSJ/Desktop/SJ/spring%20pj/scheduledPj/target/scheduledPj-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/logback-classic-1.2.3.

我尝试执行
java-jar jarname.jar
,但出现了一个错误

然而,如果我在STS上启动该项目,我不会从以前得到错误

我不明白为什么它不工作,为什么STS工作,而jar也不工作

SLF4J: Found binding in [jar:file:/C:/Users/YSJ/Desktop/SJ/spring%20pj/scheduledPj/target/scheduledPj-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/YSJ/Desktop/SJ/spring%20pj/scheduledPj/target/scheduledPj-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/slf4j-log4j12-1.7.28.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.0.RELEASE)

2019-10-31 16:22:19.283  INFO 3952 --- [           main] com.scheduledPj.ScheduledPjApplication   : Starting ScheduledPjApplication v0.0.1-SNAPSHOT on KC20114 with PID 3952 (C:\Users\YSJ\Desktop\SJ\spring pj\scheduledPj\target\scheduledPj-0.0.1-SNAPSHOT.jar started by YSJ in C:\Users\YSJ\Desktop\SJ\spring pj\scheduledPj\target)
2019-10-31 16:22:19.289  INFO 3952 --- [           main] com.scheduledPj.ScheduledPjApplication   : No active profile set, falling back to default profiles: default
2019-10-31 16:22:20.284  WARN 3952 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : No MyBatis mapper was found in '[com.dao]' package. Please check your configuration.
2019-10-31 16:22:20.465  WARN 3952 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : No MyBatis mapper was found in '[com.scheduledPj]' package. Please check your configuration.
2019-10-31 16:22:22.790  INFO 3952 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-10-31 16:22:22.801  INFO 3952 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-10-31 16:22:22.801  INFO 3952 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.27]
2019-10-31 16:22:22.899  INFO 3952 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-10-31 16:22:22.900  INFO 3952 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3493 ms
2019-10-31 16:22:23.029  WARN 3952 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataController': Unsatisfied dependency expressed through field 'dataService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataService': Unsatisfied dependency expressed through field 'dataDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataDao': Unsatisfied dependency expressed through field 'sqlSession'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionTemplate' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionTemplate' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2019-10-31 16:22:23.035  INFO 3952 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2019-10-31 16:22:23.105  INFO 3952 --- [           main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-10-31 16:22:23.108 ERROR 3952 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   :

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
        If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
        If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

您是否进行了任何特定的配置或设置?

在STS中,您似乎以某种方式配置了参数
url
。如果使用
java-jar
启动应用程序,还必须提供参数。例如:
java-jar myspringbootapp.jar--url=jdbc:blabla

依赖项:
Dependencies:<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <scope>runtime</scope>
    <version>1.4.199</version>
</dependency>

Properties:
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
com.h2数据库 氢 运行时 1.4.199 特性: url=jdbc:h2:mem:testdb spring.datasource.driverClassName=org.h2.Driver spring.datasource.username=sa spring.datasource.password=password spring.jpa.database platform=org.hibernate.dial.h2dial
只需创建新的spring start项目并创建Application.ymlIt,它似乎无法识别数据库的url,请检查语法或正确输入内存数据库中的h2。由于错误,它无法初始化数据源,错误必须来自该空间。[链接]请检查此空间链接:我们找不到您要查找的页面。现在应该工作了url是什么意思?你读过你的异常消息了吗<代码>配置数据源失败:“url”属性未指定,无法配置嵌入式数据源。在应用程序中使用名为
url
的属性。因此,您必须以某种方式指定它。Spring boot仅在测试环境中使用默认H2数据库。在任何其他环境中,您都必须指定您的数据源。我在aplication.yml中添加了mssql jdbc依赖项并添加了db url,因此它在STS上工作,而不是在java上工作-您可以与config spring:datasource:url:jdbc共享属性yaml吗sqlserver://127.0.0.1:8443;databasename=备份驱动程序类名:net.sf.log4jdbc.sql.jdbcapi.DriverSpyusername:1234密码:1234