【发布时间】:2021-03-23 13:56:05
【问题描述】:
我最近注册了一个免费网站,网址是http://kensinelli.infinityfreeapp.com。我正在尝试学习 Spring MVC,而不是在 localhost:8080 上做所有事情,我想在一个实际的网站上做所有事情,以便潜在的雇主可以轻松地看到我决定创建的任何内容。但是,我一直在努力弄清楚如何做到这一点。我用谷歌搜索了很多,发现一些资源提到了 application.properties 文件,我设置了 server.address = http://kensinelli.infinityfreeapp.com 和 server.port = 80。我也尝试设置 server.address = 185.27 .134.151 是网站控制面板中规定的 IP 地址。当我使用 IP 地址并尝试启动 Spring 时,出现错误:
org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
当我使用 http://kensinelli.infinityfreeapp.com 而不是 IP 地址时,我收到此错误:
Failed to bind properties under 'server.address' to java.net.InetAddress:
Property: server.address
Value: http://kensinelli.infinityfreeapp.com
Origin: class path resource [application.properties] - 1:16
Reason: failed to convert java.lang.String to java.net.InetAddress
Action:
Update your application's configuration
所以我认为 server.address 应该是一个实际的 IP 地址,而不是通过 DNS 运行的命名服务器地址。
但是我什至需要通过 Spring 的内置 Tomcat 来执行此操作吗?我可以以某种方式绕过它,还是需要 Tomcat 才能连接到外部网站?
我的文件目前是这样的:
package spring.project;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class WebProjectApplication {
public static void main(String[] args) {
SpringApplication.run(WebProjectApplication.class, args);
System.out.println("Hello world");
}
}
pom.xml(一些依赖项被注释掉了,因为我计划在未来使用它们,但它们现在在启动时导致我出错):
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>spring.project</groupId>
<artifactId>webProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>webProject</name>
<description>spring project</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<!-- <dependency> -->
<!-- <groupId>org.springframework.boot</groupId> -->
<!-- <artifactId>spring-boot-starter-jdbc</artifactId> -->
<!-- </dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.springframework.boot</groupId> -->
<!-- <artifactId>spring-boot-starter-thymeleaf</artifactId> -->
<!-- </dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.thymeleaf.extras</groupId> -->
<!-- <artifactId>thymeleaf-extras-springsecurity5</artifactId> -->
<!-- </dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.postgresql</groupId> -->
<!-- <artifactId>postgresql</artifactId> -->
<!-- <scope>runtime</scope> -->
<!-- </dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.properties:
server.address=185.27.134.151
server.port=80
我知道我的代码此时没有做任何事情,但我只是想让它立即开始而没有错误。我在这方面真的很新,所以请不要以为我什么都知道。一步一步的演练将不胜感激。请不要只说“阅读文档”,因为我已经看过它,要么我没有找到我正在寻找的东西,要么不理解它,所以我需要有人来澄清一下。谢谢。
【问题讨论】:
标签: html spring spring-mvc web