本地启动原神!
但是本机访问不到页面
IDEA中启动项目就可以访问的到
jar包部署到云服务器上也无法访问 安全组也开放了
错误原因:Spring boot如果只是打jar包,这样即可,但是打包不了webapp目录下的资源,所以运行jar包访问不到页面。
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
推荐的前端模版引擎是thymeleaf,所以对于jsp的支持可能存在兼容性问题。
在pom.xml文件中加入resources配置
如果没有配置<targetPath>META-INF/resources</targetPath>,src/main/webapp的内容会保存到BOOT-INF/ 目录下。经测试,jsp页面无法正常访问,需要指定到META-INF/resources才能正常访问
<build>
<resources>
<resource>
<directory>src/main/webapp</directory>
<targetPath>META-INF/resources</targetPath>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
spring-boot-maven-plugin的版本指定为1.4.2.RELEASE
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- 一定要是这个版本,其他版本访问不到页面 -->
<version>1.4.2.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- 1.4.2.RELEASE导致多个main方法的情况下需要指定主类 -->
<mainClass>com.xxx.xxx.xxxApplication</mainClass>
</configuration>
</plugin>
</plugins>
</build>
配置完成之后,重新打jar包运行,现在就可以访问页面了。