我是后端开发的新手,在追踪此问题方面有些困难。解决此问题的其他解决方案包括属性文件本身中的语法错误,但我认为我认为还可以。
我的团队继承了一个Spring Boot应用程序,并且在设置和运行时,我是唯一一个应用程序无法启动的应用程序。我的设置中是否可能有什么导致此绑定问题?
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under 'abc.def-port' to int:
Property: abc.defport
Value: ###DEF_PORT###
Origin: "abc.defPort" from property source "class path resource [ def.properties]"
Reason: failed to convert java.lang.String to int
Action:
Update your application's configuration
, , THREAD_ID=main, STACK_TRACE=]
这是我的 Application.java 文件,它指向此配置文件:
@SpringBootApplication
@PropertySource({ "classpath:application.properties",
"classpath:def.properties" })
@EnableMonitoring
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class
})
@EnableDEF
public class Application extends SpringBootServletInitializer
{
public static void main(String[] args)
{
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder
configure(SpringApplicationBuilder application)
{
return application.sources(Application.class);
}
}
这是我的 def.properties 文件:
#abc.defHost=my-content-def-test.company.com
#abc.defPort=443
abc.defHost=###DEF_HOST###
abc.defPort=###DEF_PORT###
主机和端口属性在另一个文件中定义,如下所示:
DEF_HOST=my-content-def-test.company.com
DEF_PORT=443
这里有什么问题会导致仅我的应用无法在本地运行?感谢您提供任何有用的提示。
********* ==============更新========== ************ *********采用以下解决方案***********************
pom.xml 中的构建配置文件使用Windows,而我是Mac上的唯一配置文件:
<profile>
<id>dev</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<properties>
<hostname>${env.COMPUTERNAME}</hostname>
<toggleDevelopmentFiltering>true</toggleDevelopmentFiltering>
</properties>
<build>
<filters>
<filter>${dev-resources.dir}/master_file.DVLP</filter>
<filter>${dev-resources.dir}/secure_file.DVLP</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<delimiters>
<delimiter>###</delimiter>
</delimiters>
<useDefaultDelimiters>false</useDefaultDelimiters>
</configuration>
</plugin>
</plugins>
</build>
</profile>
我应该像这样创建一个新的配置文件:
<profile>
<id>dev-mac</id>
<activation>
<os>
<family>mac</family>
</os>
</activation>
<properties>
<hostname>${env.COMPUTERNAME}</hostname>
<toggleDevelopmentFiltering>true</toggleDevelopmentFiltering>
</properties>
<build>
<filters>
<filter>${dev-resources.dir}/master_file.DVLP</filter>
<filter>${dev-resources.dir}/secure_file.DVLP</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<delimiters>
<delimiter>###</delimiter>
</delimiters>
<useDefaultDelimiters>false</useDefaultDelimiters>
</configuration>
</plugin>
</plugins>
</build>
</profile>