我想将Spark参数(如输入文件,输出文件)存储到Java属性文件中,并将该文件传递给Spark Driver.我使用spark-submit提交作业但找不到传递属性文件的参数.你有什么建议吗?
我有一个Spring-Boot-Application作为maven中的multimodule-Project.结构如下:
Parent-Project
|--MainApplication
|--Module1
|--ModuleN
Run Code Online (Sandbox Code Playgroud)
在MainApplication项目中有main()方法类注释用@SpringBootApplication等等.此项目一如既往地自动加载application.properties文件.所以我可以使用@Value注释访问值
@Value("${myapp.api-key}")
private String apiKey;
Run Code Online (Sandbox Code Playgroud)
在我的Module1中,我也想使用属性文件(称为module1.properties),其中存储了模块配置.只能在模块中访问和使用此文件.但是我无法加载它.我尝试过@Configuration,@PropertySource但没有运气.
@Configuration
@PropertySource(value = "classpath:module1.properties")
public class ConfigClass {
Run Code Online (Sandbox Code Playgroud)
如何使用Spring-Boot加载属性文件并轻松访问这些值?找不到有效的解决方案.
我的配置
@Configuration
@PropertySource(value = "classpath:tmdb.properties")
public class TMDbConfig {
@Value("${moviedb.tmdb.api-key}")
private String apiKey;
public String getApiKey() {
return apiKey;
}
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
Run Code Online (Sandbox Code Playgroud)
调用配置
@Component
public class TMDbWarper {
@Autowired
private TMDbConfig tmdbConfig;
private TmdbApi tmdbApi;
public TMDbWarper(){
tmdbApi = …Run Code Online (Sandbox Code Playgroud) 是否可以在Java中堆叠加载的属性?比如我可以这样做:
Properties properties = new Properties();
properties.load(new FileInputStream("file1.properties"));
properties.load(new FileInputStream("file2.properties"));
Run Code Online (Sandbox Code Playgroud)
并从两者访问属性?
我想从建造的jar中排除 AMAuthN.properties.此文件一直显示在已编译jar的根文件夹中.该文件位于AMAuthN\src\main\resources\AMAuthN.properties项目文件夹根目录下.谢谢!
apply plugin: 'java'
apply plugin: 'eclipse'
version = '1.0'
sourceCompatibility = 1.6
targetCompatibility = 1.6
test {
testLogging {
showStandardStreams = true
}
}
// Create a single Jar with all dependencies
jar {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'com.axa.openam'
}
baseName = project.name
from {
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
}
// Get dependencies from Maven central repository
repositories {
mavenCentral()
}
// …Run Code Online (Sandbox Code Playgroud) Properties myProp = new Properties();
myProp.put("material", "steel");
Properties prop1 = new Properties(myProp);
System.out.println(prop1.get("material") + ", " + prop1.getProperty("material"));
// outputs "null, steel"
Run Code Online (Sandbox Code Playgroud)
在它返回Object的条目/属性的意义上,是否与getProperty类似?使用get时为什么不返回'steel'?
我有一个类似的文件
name1=value1
name2=value2
Run Code Online (Sandbox Code Playgroud)
我需要使用shell脚本和设置变量来读取此文件
$name1=value1
$name2=value2
Run Code Online (Sandbox Code Playgroud)
请提供可以执行此操作的脚本.
我尝试了下面的第一个答案,即获取属性文件,但如果值包含空格,我会遇到问题.它被解释为空格后的新命令.如何让它在空间存在的情况下工作?
我有一个带有PropertyPlaceholderConfigurer的Spring application-context.xml,用于从.properties文件中获取属性值.主文件夹和测试源文件夹具有单独的.properties文件.问题是我需要在.properties文件中使用环境变量.但是,当我按以下方式执行此操作时:
property.name=${env.SYSTEM_PROPERTY}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'beanName' defined in class path resource [com/example/applicationContext.xml]: Could not resolve placeholder 'env.SYSTEM_PROPERTY'
Run Code Online (Sandbox Code Playgroud)
而占位符配置器定义为
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:com/example/application.properties"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
任何想法如何使property.name被解释为环境变量(而不是占位符)?
最好的问候,德米特里.
java spring environment-variables properties-file applicationcontext
我目前正在实现此处建议的API密钥切换脚本,除了使用构建类型而不是flavor.我的build.gradle看起来像这样:
...
buildTypes {
debug {
...
set("crashlyticsApiKey", "API_KEY_1")
set("crashlyticsApiSecret", "API_SECRET_1")
}
release {
...
set("crashlyticsApiKey", "API_KEY_2")
set("crashlyticsApiSecret", "API_SECRET_2")
}
}
...
productFlavors{...}
...
File crashlyticsProperties = new File("${project.projectDir.absolutePath}/crashlytics.properties")
applicationVariants.all { variant ->
variant.productFlavors.each { flavor ->
def variantSuffix = variant.name.capitalize()
def generateResourcesTask = project.tasks.getByName("crashlyticsGenerateResources${variantSuffix}")
def generatePropertiesTask = task("crashlyticsGenerateProperties${variantSuffix}") << {
Properties properties = new Properties()
println "...copying apiKey for ${variant.name}"
properties.put("apiKey", variant.buildType.crashlyticsApiKey)
println "...copying apiSecret for ${variant.name}"
properties.put("apiSecret", variant.buildType.crashlyticsApiSecret)
properties.store(new FileWriter(crashlyticsProperties), "")
}
generateResourcesTask.dependsOn generatePropertiesTask
def cleanResourcesTask …Run Code Online (Sandbox Code Playgroud) 我很少接触到SonarQube但都被要求做一个文件,解释如何设置/使用"sonar-project.properties文件".任何信息或输入将不胜感激.
properties-file ×10
java ×8
spring ×2
android ×1
apache-spark ×1
build.gradle ×1
crashlytics ×1
gradle ×1
properties ×1
shell ×1
sonar-runner ×1
sonarqube ×1
spring-boot ×1