Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Amphibian
Commits
049b94cb
Commit
049b94cb
authored
Jan 25, 2021
by
Matija Obreza
Browse files
Properties: Use PropertySourcesPlaceholderConfigurer
parent
ef05ae0e
Changes
2
Hide whitespace changes
Inline
Side-by-side
amphibian-server/src/main/java/org/genesys/amphibian/config/ApplicationConfig.java
View file @
049b94cb
...
...
@@ -20,12 +20,14 @@ import java.util.ArrayList;
import
java.util.List
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.EnableAspectJAutoProxy
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.context.support.PropertySourcesPlaceholderConfigurer
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.core.io.FileSystemResource
;
import
org.springframework.core.io.Resource
;
...
...
@@ -36,30 +38,30 @@ import org.springframework.core.io.Resource;
@Import
({
SchedulerConfig
.
class
,
DatabaseConfig
.
class
,
WebConfiguration
.
class
,
SwaggerConfig
.
class
})
@EnableAspectJAutoProxy
public
class
ApplicationConfig
{
final
static
Logger
LOG
=
LoggerFactory
.
getLogger
(
ApplicationConfig
.
class
);
@Bean
public
static
PropertyPlaceholderConfigurer
propertyPlaceholderConfigurer
()
{
final
PropertyPlaceholderConfigurer
propertyPlaceholderConfigurer
=
new
PropertyPlaceholderConfigurer
();
propertyPlaceholderConfigurer
.
setIgnoreResourceNotFound
(
true
);
propertyPlaceholderConfigurer
.
setSystemPropertiesMode
(
PropertyPlaceholderConfigurer
.
SYSTEM_PROPERTIES_MODE_OVERRIDE
);
propertyPlaceholderConfigurer
.
setFileEncoding
(
"utf-8"
);
public
static
PropertySourcesPlaceholderConfigurer
properties
()
{
PropertySourcesPlaceholderConfigurer
pspc
=
new
PropertySourcesPlaceholderConfigurer
();
pspc
.
setIgnoreResourceNotFound
(
true
);
pspc
.
setFileEncoding
(
"UTF-8"
);
pspc
.
setTrimValues
(
false
);
// this is also the default
final
List
<
Resource
>
locations
=
new
ArrayList
<>();
locations
.
add
(
new
ClassPathResource
(
"application.properties"
));
locations
.
add
(
new
ClassPathResource
(
"amphibian.properties"
));
final
String
extraConfigFile
=
System
.
getenv
(
"config.file"
);
final
String
extraConfigFile
=
StringUtils
.
defaultIfBlank
(
System
.
getenv
(
"config.file"
),
"myconfig.properties"
);
if
(
StringUtils
.
isNotBlank
(
extraConfigFile
))
{
final
File
f
=
new
File
(
extraConfigFile
);
if
(
f
.
exists
()
&&
f
.
canRead
())
{
System
.
err
.
printl
n
(
"Including properties from
config.file="
+
extraConfigFile
);
if
(
f
.
exists
()
&&
f
.
canRead
()
&&
f
.
isFile
()
)
{
LOG
.
war
n
(
"Including
extra
properties from
{}"
,
extraConfigFile
);
locations
.
add
(
new
FileSystemResource
(
extraConfigFile
));
}
else
{
System
.
err
.
println
(
"Cannot read properties from config.file="
+
extraConfigFile
);
LOG
.
warn
(
"Extra configuration file {} not found"
,
extraConfigFile
);
}
}
p
ropertyPlaceholderConfigurer
.
setLocations
(
locations
.
toArray
(
new
Resource
[]
{}));
return
p
ropertyPlaceholderConfigurer
;
p
spc
.
setLocations
(
locations
.
toArray
(
new
Resource
[]
{}));
return
p
spc
;
}
}
amphibian-server/src/main/java/org/genesys/amphibian/config/DatabaseConfig.java
View file @
049b94cb
...
...
@@ -19,6 +19,8 @@ package org.genesys.amphibian.config;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -38,6 +40,8 @@ import com.mongodb.ServerAddress;
@EnableMongoAuditing
(
modifyOnCreate
=
true
)
public
class
DatabaseConfig
extends
AbstractMongoConfiguration
{
final
static
Logger
LOG
=
LoggerFactory
.
getLogger
(
ApplicationConfig
.
class
);
@Value
(
"${mongo.hosts}"
)
private
String
[]
dbHosts
;
...
...
@@ -69,9 +73,10 @@ public class DatabaseConfig extends AbstractMongoConfiguration {
MongoClientOptions
options
=
new
MongoClientOptions
.
Builder
().
build
();
List
<
ServerAddress
>
servers
=
new
ArrayList
<>();
for
(
String
dbHost:
dbHosts
)
{
LOG
.
warn
(
"Adding mongo at {}:{}"
,
dbHost
,
dbPort
);
servers
.
add
(
new
ServerAddress
(
dbHost
,
dbPort
));
}
MongoClient
mongoClient
=
new
MongoClient
(
servers
,
credential
,
options
);
return
mongoClient
;
}
}
\ No newline at end of file
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment