[mac][Eclipse]使用JDK10在Mac上运行Java Spring程序

在Mac上运行Spring MVC和Spring Boot。
我的描述可能有些冗长。

前提 tí)

我使用了Eclipse和Maven。
https://mergedoc.osdn.jp/
我安装了Java EE。SE版本没有服务器端,只能使用swing等。
https://codeaid.jp/eclipse-java-mac/

在Eclipse中,如果没有市场中心,您可以通过帮助选项卡安装插件。

运行Maven项目于eclipse
https://qiita.com/tarosa0001/items/e5667cfa857529900216

春季启动器

春季引擎环境设置

这次决定不直接使用Spring Tool Suite。

从Eclipse市场中安装Spring Boot工具的插件。

使用Spring Boot创建的Hello World项目

我认为这个初始化器也可以用来生成。

我认为即使使用Maven也可以生成。

示例实现一

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class DemoApplication {

    @RequestMapping("/")
    String hello() {
        return "Hello Spring Boot!";
    }

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

在中国国内,使用以下链接进行上载:
http://localhost:8080/

样品实施2

春季MVC

嗯,啊!端口被占用了吗?如果是的话,考虑确认并关闭它。

lsof -i :8080
├── pom.xml
├── src
│   ├── main
│   │   ├── java
│   │   │   └── com
│   │   │       └── spring
│   │   │           └── mvc
│   │   │               ├── GreetController.java
│   │   │               └── HomeController.java
│   │   ├── resources
│   │   │   ├── META-INF
│   │   │   └── log4j.xml
│   │   └── webapp
│   │       ├── WEB-INF
│   │       │   ├── classes
│   │       │   ├── spring
│   │       │   │   ├── appServlet
│   │       │   │   │   └── servlet-context.xml
│   │       │   │   └── root-context.xml
│   │       │   ├── views
│   │       │   │   ├── greet.jsp
│   │       │   │   └── home.jsp
│   │       │   └── web.xml
│   │       └── resources
│   └── test
│       ├── java
│       │   └── com
│       │       └── spring
│       │           └── mvc
│       └── resources
│           └── log4j.xml
└── target
    ├── classes
    │   ├── com
    │   │   └── spring
    │   │       └── mvc
    │   │           ├── GreetController.class
    │   │           └── HomeController.class
    │   └── log4j.xml
    ├── m2e-wtp
    │   └── web-resources
    │       └── META-INF
    │           ├── MANIFEST.MF
    │           └── maven
    │               └── com.spring
    │                   └── mvc
    │                       ├── pom.properties
    │                       └── pom.xml
    └── test-classes
        ├── com
        │   └── spring
        │       └── mvc
        └── log4j.xml
package com.spring.mvc;

import java.util.Locale;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;


/**
 * Handles requests for the application home page.
 */
@Controller
public class GreetController {


    /**
     * Simply selects the home view to render by returning its name.
     */
    @RequestMapping(value = "/greet", method = RequestMethod.GET)
    public String greet(Locale locale, Model model) {
        model.addAttribute("str1", "iiiii");
        return "greet";
    }

}

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Greet</title>
</head>
<body>
    <P>  The time on the server is ${str1}. </P>
</body>
</html>

只有把eclipse和tomcat连接起来,才能执行。
下载tomcat,利用JDBC连接mysql,将tomcat文件夹设置到eclipse中即可。
这里提供参考。

以下是2.3. “初次使用Spring MVC应用程序”的中文释义:
请查阅:https://terasolunaorg.github.io/guideline/public_review/Overview/FirstApplication.html

使用Spring MVC提供Web内容

使用Java Config的Spring MVC

以下是您提供的两个链接:


请注意只需要一个选项。

样本
https://qiita.com/neriai/items/6b27fba2aa1af7b60bb8
https://sites.google.com/site/soracane/home/springnitsuite/spring-mvc/05-shi-jinosanpuru
http://terasolunaorg.github.io/guideline/5.5.1.RELEASE/ja/Overview/FirstApplication.html
https://qiita.com/t-shin0hara/items/c7d08aaef24fcdd64a28

IntelliJ的时候

[Ubuntu18/mac][IntelliJ]在jdk10下启动tomcat9
https://qiita.com/miyamotok0105/items/3f5e429d80cfe2ca3f32

故障排除

当端口被堵塞时

查询显示所有使用端口号为1080的网络连接。

Alternatively:

检查所有使用1080端口的网络连接信息。

bannerAds