Java 在没有Maven的情况下使用Spring引导

Java 在没有Maven的情况下使用Spring引导,java,spring-boot,maven,tomcat,microservices,Java,Spring Boot,Maven,Tomcat,Microservices,我正试图编写一个简单的Java程序,将Hello World显示为一个微服务。我正在使用Spring Boot,但由于公司的安全原因,我无法使用Maven。因此,我别无选择,只能下载jar文件并将它们添加到我的项目中。我已经这样做了,并确保我使用的是最新的jar版本。当我运行我的程序时,它没有显示任何错误,但是Tomcat服务器没有启动,并且我没有看到“Hello World”消息。下面是我的代码: package com.tutorials; import org.springframewor

我正试图编写一个简单的Java程序,将Hello World显示为一个微服务。我正在使用Spring Boot,但由于公司的安全原因,我无法使用Maven。因此,我别无选择,只能下载jar文件并将它们添加到我的项目中。我已经这样做了,并确保我使用的是最新的jar版本。当我运行我的程序时,它没有显示任何错误,但是Tomcat服务器没有启动,并且我没有看到“Hello World”消息。下面是我的代码:

package com.tutorials;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@EnableAutoConfiguration
public class HelloWorld {

    @RequestMapping("/")
    //http://localhost:port/

    String hello()
    {
        return "Hello World!";
    }

    public static void main(String[] args) throws Exception{

        SpringApplication.run(HelloWorld.class,args);
        System.out.println("done");


    }



}
以下是输出:

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

2020-01-07 11:10:44.563  INFO 13224 --- [           main] com.tutorials.HelloWorld                 : Starting HelloWorld on HQTPM00184606D with PID 13224 (started by z.a in C:\Users\Z\Desktop\Workspace\HelloWorld_Microservice)
2020-01-07 11:10:44.566  INFO 13224 --- [           main] com.tutorials.HelloWorld                 : No active profile set, falling back to default profiles: default
2020-01-07 11:10:44.938  INFO 13224 --- [           main] com.tutorials.HelloWorld                 : Started HelloWorld in 0.703 seconds (JVM running for 1.096)
done
下面是我正在使用的jar文件:


为什么Tomcat没有启动,我在这里缺少哪些依赖项?谢谢。

spring boot starter web 2.2.2的依赖关系树是:

org.springframework.boot:spring-boot-starter-web:jar:2.2.2.RELEASE:compile
+- org.springframework.boot:spring-boot-starter:jar:2.2.2.RELEASE:compile
|  +- org.springframework.boot:spring-boot:jar:2.2.2.RELEASE:compile
|  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.2.2.RELEASE:compile
|  +- org.springframework.boot:spring-boot-starter-logging:jar:2.2.2.RELEASE:compile
|  |  +- ch.qos.logback:logback-classic:jar:1.2.3:compile
|  |  |  +- ch.qos.logback:logback-core:jar:1.2.3:compile
|  |  |  \- org.slf4j:slf4j-api:jar:1.7.29:compile
|  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.12.1:compile
|  |  |  \- org.apache.logging.log4j:log4j-api:jar:2.12.1:compile
|  |  \- org.slf4j:jul-to-slf4j:jar:1.7.29:compile
|  +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile
|  +- org.springframework:spring-core:jar:5.2.2.RELEASE:compile
|  |  \- org.springframework:spring-jcl:jar:5.2.2.RELEASE:compile
|  \- org.yaml:snakeyaml:jar:1.25:runtime
+- org.springframework.boot:spring-boot-starter-json:jar:2.2.2.RELEASE:compile
|  +- com.fasterxml.jackson.core:jackson-databind:jar:2.10.1:compile
|  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.10.1:compile
|  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.10.1:compile
|  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.10.1:compile
|  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.10.1:compile
|  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.10.1:compile
+- org.springframework.boot:spring-boot-starter-tomcat:jar:2.2.2.RELEASE:compile
|  +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.29:compile
|  +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.29:compile
|  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.29:compile
+- org.springframework.boot:spring-boot-starter-validation:jar:2.2.2.RELEASE:compile
|  +- jakarta.validation:jakarta.validation-api:jar:2.0.1:compile
|  \- org.hibernate.validator:hibernate-validator:jar:6.0.18.Final:compile
|     +- org.jboss.logging:jboss-logging:jar:3.4.1.Final:compile
|     \- com.fasterxml:classmate:jar:1.5.1:compile
+- org.springframework:spring-web:jar:5.2.2.RELEASE:compile
|  \- org.springframework:spring-beans:jar:5.2.2.RELEASE:compile
\- org.springframework:spring-webmvc:jar:5.2.2.RELEASE:compile
   +- org.springframework:spring-aop:jar:5.2.2.RELEASE:compile
   +- org.springframework:spring-context:jar:5.2.2.RELEASE:compile
   \- org.springframework:spring-expression:jar:5.2.2.RELEASE:compile

但是正如评论中提到的,您应该尝试使用构建工具(Maven/Gradle)和公司范围的存储库管理器(Nexus/Artifactory)。

您是否尝试过将
hello()
作为公共方法?您似乎也缺少了类级别的
@SpringBootApplication
注释。旁注:“由于我公司的安全原因,我无法使用Maven”->我真的会对此提出挑战,因为如果您不能使用像Maven或Gradle这样的适当构建工具,您的生活将非常艰难。如果他们不想从互联网上下载,他们可以安装一个像或这样的公司存储库。你真的需要像Maven或Gradle这样的东西来使用SpringBoot。它创建的jar/war有一个特殊的包装和特殊的启动方式。如果没有Maven或Gradle,您需要确保自己也复制了它,否则交付的工件将无法工作。