@Component
@Configuration
@EnableCassandraRepositories(basePackages = "uk.co.dashboard.repository")
@PropertySource(value="file:${env.properties.location}/application.properties")
public class CassandraConfiguration {
@Value("${cassandra.contactpoints}")
private String[] cassandraContactPoint;
@Value("${cassandra.port}")
private Integer cassandraPort;
@Value("${cassandra.keyspace}")
private String keyspaceName;
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
@Bean
public MappingManager mappingManager(@Qualifier("session") Session session) {
return new MappingManager(session);
}
@Bean
public Session session() {
Cluster cluster = connectToCluster();
Session session = cluster.connect(keyspaceName);
return session;
}
@Bean
public DataRepository dataRepository(MappingManager mappingManager){
return mappingManager.createAccessor(DataRepository.class);
}
public Cluster connectToCluster() {
QueryOptions queryOptions = new QueryOptions();
queryOptions.setConsistencyLevel(ConsistencyLevel.QUORUM);
Cluster cluster = Cluster.builder()
.addContactPoints(cassandraContactPoint)
.withPort(cassandraPort)
.withQueryOptions(queryOptions)
.build();
return cluster;
}
protected String getKeyspaceName() {
return keyspaceName;
}
@Bean
public BasedataService basedataService(){
return new BasedataService();
}
java-jar basedata-dashboard-1.0.0-snapshot.jar-denv.properties.location='/home/desktop‘
在我的桌面上,是一个名为application.properties的文件,其中包含配置详细信息。但是,当运行上面的命令时,我得到:
2018-12-04 14:48:09.103 ERROR 9964 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [uk.co.dashboard.Application]; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'env.properties.location' in value "file:${env.properties.location}/application.properties"
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:184) ~[spring-context-5.0.11.RELEASE.jar!/:5.0.11.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:316) ~[spring-context-5.0.11.RELEASE.jar!/:5.0.11.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) ~[spring-context-5.0.11.RELEASE.jar!/:5.0.11.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:271) ~[spring-context-5.0.11.RELEASE.jar!/:5.0.11.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:91) ~[spring-context-5.0.11.RELEASE.jar!/:5.0.11.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:692) ~[spring-context-5.0.11.RELEASE.jar!/:5.0.11.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:530) ~[spring-context-5.0.11.RELEASE.jar!/:5.0.11.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.0.7.RELEASE.jar!/:2.0.7.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) [spring-boot-2.0.7.RELEASE.jar!/:2.0.7.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) [spring-boot-2.0.7.RELEASE.jar!/:2.0.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-2.0.7.RELEASE.jar!/:2.0.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242) [spring-boot-2.0.7.RELEASE.jar!/:2.0.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230) [spring-boot-2.0.7.RELEASE.jar!/:2.0.7.RELEASE]
at uk.co.hermes.hubsanddepots.basedata.dashboard.Application.main(Application.java:11) [classes!/:1.0.0-SNAPSHOT]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [basedata-dashboard-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [basedata-dashboard-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [basedata-dashboard-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [basedata-dashboard-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'env.properties.location' in value "file:${env.properties.location}/application.properties"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:172) ~[spring-core-5.0.11.RELEASE.jar!/:5.0.11.RELEASE]
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124) ~[spring-core-5.0.11.RELEASE.jar!/:5.0.11.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:237) ~[spring-core-5.0.11.RELEASE.jar!/:5.0.11.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:211) ~[spring-core-5.0.11.RELEASE.jar!/:5.0.11.RELEASE]
at org.springframework.core.env.AbstractEnvironment.resolveRequiredPlaceholders(AbstractEnvironment.java:571) ~[spring-core-5.0.11.RELEASE.jar!/:5.0.11.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.processPropertySource(ConfigurationClassParser.java:451) ~[spring-context-5.0.11.RELEASE.jar!/:5.0.11.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:272) ~[spring-context-5.0.11.RELEASE.jar!/:5.0.11.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245) ~[spring-context-5.0.11.RELEASE.jar!/:5.0.11.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:194) ~[spring-context-5.0.11.RELEASE.jar!/:5.0.11.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:296) ~[spring-context-5.0.11.RELEASE.jar!/:5.0.11.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245) ~[spring-context-5.0.11.RELEASE.jar!/:5.0.11.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:202) ~[spring-context-5.0.11.RELEASE.jar!/:5.0.11.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:170) ~[spring-context-5.0.11.RELEASE.jar!/:5.0.11.RELEASE]
现在,当我在工作目录中有application.properties的本地副本时,我的应用程序就可以工作了。然而,这对于意图来说是不可行的,我需要能够通过控制台ping应用程序,并在这样做时提供application.properties文件,因为这些变量将会改变和/或应用程序将用于不同的目的。
我在网上找了很长时间,但我真的卡住了,我觉得我读过的大多数东西都告诉我它设置正确,但我不明白为什么它不工作。
最后我要包括的是我的pom:
<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>uk.co.dashboard.</groupId>
<artifactIddashboard</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>Dashboard</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.7.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring4</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-mapping</artifactId>
<version>2.1.6</version>
</dependency>
<dependency>
<groupId>uk.co.hermes</groupId>
<artifactId>basedata-cassandra-entities</artifactId>
<version>1.21</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.22</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.cassandraunit</groupId>
<artifactId>cassandra-unit</artifactId>
<version>1.0.1.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.8.RELEASE</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<!--<classifier>jwd</classifier>-->
<!--<finalName>markiv</finalName>-->
<mainClass>uk.co.hermes.hubsanddepots.basedata.dashboard.Application</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
当在-jar选项之前提供JAVA_OPTS时,java的命令行参数可以很好地工作。
我在最初的时候也遇到过类似的问题,并且能够通过在-jar选项之前更改系统属性来解决这个问题。
请尝试使用以下命令行选项:
在我的项目中,我想使用特定于环境的属性文件。例如,如果我在开发中运行它,它应该使用应用程序。dev.properties,对于生产,它应该使用应用程序。产品属性等等。 我有下面两个文件在我的资源文件夹。 application.properties(用于生产) application.dev.properties(用于开发) 我有一个属性像下面的每个文件。 为了刺激 给德夫 我有一门课,如下所示
本文向大家介绍怎么将 SpringBoot web 应用程序部署为 JAR 或 WAR 文件?相关面试题,主要包含被问及怎么将 SpringBoot web 应用程序部署为 JAR 或 WAR 文件?时的应答技巧和注意事项,需要的朋友参考一下 通常,我们将 web 应用程序打包成 WAR 文件,然后将它部署到另外的服务器上。这样做使得我们能够在相同的服务器上处理多个项目。当 CPU 和内存有限的情
完成干净的构建后,我将war文件复制到Tomcat的文件夹中。但是部署会发生两次,并且在上下文已经存在的情况下以异常结束。我错过了什么? 非常感谢您的帮助。
更新: 这会导致我的应用程序出现错误,因为其他bean无法初始化。奇怪的是它在Eclipse上运行得很好。 我有一个名为DataService的类,它扩展了JDBCTemplate。在我的DataService构造函数中,我注入了数据源。 我在其他bean中使用这个DataService类来执行DB操作。我的数据源在我的文件中定义 这是我的application.java类 当我尝试使用Maven
问题内容: 我对将外部应用程序嵌入基于QT 5.5 Widget的应用程序感兴趣。我只关心它在Linux上的工作。我在GNOME上使用CentOS 7。 这是我尝试过的代码: 在此示例中,我将分别获取WinId,并仅对值进行硬编码以进行测试。要嵌入的应用程序正在运行。 当我执行我的应用程序时,它运行没有错误。并且要嵌入的应用程序会更改屏幕位置并调整其大小,但是不会嵌入到我的应用程序中。它仍然是一个