Windows 10 上使用 Maven 和 Jetty 的 Java 应用程序:HTTP 错误:503 访问 / 时出现问题。原因:服务不可用

问题描述 投票:0回答:1

我尝试在 Windows 10 上使用

mvn -Dluke.confdir=file://C:\\ecoconfig\\ecomodules-calculation.conf jetty:run
从命令提示符运行一个大约有九年历史的 Java 应用程序,它会给出以下警告(三个点代表各个文件中的很多行):

[WARNING] Failed startup of context o.e.j.m.p.JettyWebAppContext@6bb1d205{/,[file:///C:/Users/03260585/Work%
20Folders/ecomodules-calculation/WebContent/, jar:file:///C:/Users/03260585/.m2/repository/io/springfox/
springfox-swagger-ui/2.8.0/springfox-swagger-ui-2.8.0.jar!/META-INF/resources],STARTING}
{file:///C:/Users/03260585/Work%20Folders/ecomodules-calculation/WebContent/}
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'org.springframework.context.support.PropertySourcesPlaceholderConfigurer#0': 
Cannot resolve reference to bean 'propertyConfigurer' while setting bean property 'properties'; 
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'propertyConfigurer': Invocation of init method failed; nested exception is java.net.UnknownHostException: C
...
...
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'propertyConfigurer': Invocation of init method failed; nested exception is java.net.UnknownHostException: C
...
...
...
Caused by: java.net.UnknownHostException: C

使用单个

\
而不是
\\
并将文件路径用单引号或双引号引起来会产生相同的警告。以下行来自
applicationContext.xml

<util:properties id="propertyConfigurer" location="${luke.confdir}/ecomodules-calculation.conf" />

并且我怀疑如果我的初始命令在文件路径格式上没有问题,那么我按照留下的说明填写的

.conf
文件 以前的开发者有问题的内容。
.conf
文件如下,我注释掉了最后两行,因为在 剩余的开发过程。除我插入的
jdbc.username
jdbc.password
jwt.secret
之外,所有内容均已预先填写。

jdbc.driverClassName=org.postgresql.Driver
jdbc.url=jdbc:postgresql://localhost:5432/ecomodules?currentSchema=ecomodules
# Database username. Probably ecomodules. Configure as appropriate.
jdbc.username=correct_username
# Database user password. Configure as appropriate.
jdbc.password=correct_password

# Generate at least 256-bit key here
# example using openssl command:
# openssl rand -base64 32
# for convenience, here is one: /e+Azj4FkSAhlwtg0yyvcUPulrtxS66pRgvF04vNvvg=
# do not use it for other than local dev environments since it's not a platform secret
jwt.secret=7e+Azj4FkSAhlwtg0yyvcUPulrtxS66pRgvF04vNvvgt
jwt.issuer=Luonnonvarakeskus
jwt.cookieName=ECOMODULES_COOKIE
jwt.ttl=P7D

# SMTP service hostname for forgot password mechanism. smtprelay.ns.luke.fi in luke internal usage
#spring.mail.host=
#spring.mail.port=25

该应用程序在

localhost:8080/
上提供,上面写着

HTTP ERROR: 503
Problem accessing /. Reason: 
Service Unavailable

我也尝试了

localhost:8080/index.html
,但那里显示了相同的错误。有人可以告诉我这里有什么问题吗?如何才能让应用程序正常运行?我没有 Java 开发经验,所以我对此很迷茫。

java -version

openjdk version "1.8.0_392"
OpenJDK Runtime Environment (Temurin)(build 1.8.0_392-b08)
OpenJDK 64-Bit Server VM (Temurin)(build 25.392-b08, mixed mode)

javac -version

javac 1.8.0_392

mvn -version

Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae)
Maven home: C:\Program Files\Maven\apache-maven-3.9.6
Java version: 1.8.0_392, vendor: Temurin, runtime: C:\Program Files\Java\jdk-8.0.392.8\jre
Default locale: fi_FI, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

pom.xml

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>fi.luke</groupId>
    <artifactId>ecomodules-calculation</artifactId>
    <version>1.2.20190227.1-SNAPSHOT</version>
    <name>EcoModules calculation service</name>
    <packaging>war</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <doclint>none</doclint>
    </properties>

    <scm>
        <developerConnection>scm:git:${env.GIT_SERVER}/tietohallinto/ecomodules-calculation</developerConnection>
        <tag>HEAD</tag>
    </scm>

    <distributionManagement>
        <repository>
            <id>deployment</id>
            <name>Internal Releases</name>
            <url>https://nexus.ns.luke.fi/nexus/content/repositories/releases/</url>
        </repository>
        <snapshotRepository>
            <id>deployment</id>
            <name>Internal Snapshots</name>
            <url>https://nexus.ns.luke.fi/nexus/content/repositories/snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

    <dependencies>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.4.1212</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-dbcp2</artifactId>
            <version>2.1.1</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.22</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.7.22</version>
        </dependency>
        <dependency>
            <groupId>fi.luke</groupId>
            <artifactId>ecomodules-common</artifactId>
            <version>4.30-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>1.11.6.RELEASE</version>
            <exclusions>
                <exclusion>
                    <artifactId>spring-orm</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-context</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-tx</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-beans</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-core</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-aop</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.8.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.8.0</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>2.6.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-webapp</artifactId>
            <version>9.3.7.v20160115</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt -->
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.googlecode.owasp-java-html-sanitizer/owasp-java-html-sanitizer -->
        <dependency>
            <groupId>com.googlecode.owasp-java-html-sanitizer</groupId>
            <artifactId>owasp-java-html-sanitizer</artifactId>
            <version>r239</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>4.3.10.RELEASE</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>ecomodules-calculation</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <argLine>-Dfile.encoding=UTF-8</argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <systemPropertyVariables>
                        <file.encoding>UTF-8</file.encoding>
                    </systemPropertyVariables>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <parameters>true</parameters>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.0.0</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.5</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5.3</version>
                <configuration>
                    <tagNameFormat>@{project.version}</tagNameFormat>
                    <preparationGoals>clean</preparationGoals><!-- default is "clean verify" -->
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <archive>
                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.3.7.v20160115</version>
                <configuration>
                    <stopPort>9966</stopPort>
                    <stopKey>sidfhsdfh</stopKey>
                    <scanIntervalSeconds>0</scanIntervalSeconds>
                    <webAppConfig>
                        <contextPath>/</contextPath>
                    </webAppConfig>
                    <webAppSourceDirectory>${basedir}/WebContent</webAppSourceDirectory>
                </configuration>
            </plugin>
        
            <plugin>
              <groupId>org.sonatype.ossindex.maven</groupId>
              <artifactId>ossindex-maven-plugin</artifactId>
              <version>3.1.0</version>
              <configuration>
                <fail>false</fail>
              </configuration>
              <executions>
                <execution>
                  <id>audit-dependencies</id>
                  <phase>validate</phase>
                  <goals>
                    <goal>audit</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
        
        </plugins>
        <resources>
            <resource>
                <directory>properties</directory>
                <includes>
                    <include>constant.properties</include>
                </includes>
            </resource>
        </resources>
    </build>

    <reporting>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>findbugs-maven-plugin</artifactId>
                <version>3.0.4</version>
                <configuration>
                    <excludeFilterFile>FindbugsExcludeFilter.xml</excludeFilterFile>
                    <effort>Max</effort>
                    <threshold>Low</threshold>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.0.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-project-info-reports-plugin</artifactId>
                <version>2.8.1</version>
            </plugin>
        </plugins>
    </reporting>
</project>
java maven java-8 maven-jetty-plugin
1个回答
0
投票

重新安装 Maven 和 Node.js 并取消注释

.conf
文件中的最后几行解决了该问题。事实证明,即使未使用密码恢复,启动应用程序时
spring.mail.host
spring.mail.port
也应在
.conf
文件中具有值。

© www.soinside.com 2019 - 2024. All rights reserved.