Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-cloud-netflix
Commits
0f281bc9
Commit
0f281bc9
authored
Dec 04, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initialize log4j to prevent blitz4j from freaking out
parent
4e2148d6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
26 deletions
+34
-26
EurekaServerInitializerConfiguration.java
...x/eureka/server/EurekaServerInitializerConfiguration.java
+32
-15
Log4JLoggingSystemTests.java
.../cloud/netflix/eureka/server/Log4JLoggingSystemTests.java
+2
-11
No files found.
spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerInitializerConfiguration.java
View file @
0f281bc9
...
...
@@ -15,6 +15,7 @@
*/
package
org
.
springframework
.
cloud
.
netflix
.
eureka
.
server
;
import
java.io.IOException
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Modifier
;
...
...
@@ -30,6 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.logging.log4j.Log4JLoggingSystem
;
import
org.springframework.cloud.netflix.eureka.DataCenterAwareMarshallingStrategy
;
import
org.springframework.cloud.netflix.eureka.DiscoveryManagerInitializer
;
import
org.springframework.cloud.netflix.eureka.EurekaServerConfigBean
;
...
...
@@ -44,6 +46,7 @@ import org.springframework.context.SmartLifecycle;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.util.ReflectionUtils
;
import
org.springframework.web.context.ServletContextAware
;
...
...
@@ -84,27 +87,40 @@ public class EurekaServerInitializerConfiguration implements ServletContextAware
this
.
servletContext
=
servletContext
;
}
@Bean
@ConditionalOnMissingBean
(
DiscoveryManagerInitializer
.
class
)
public
DiscoveryManagerInitializer
discoveryManagerIntitializer
()
{
return
new
DiscoveryManagerInitializer
();
}
@Bean
@ConditionalOnMissingBean
(
DiscoveryManagerInitializer
.
class
)
public
DiscoveryManagerInitializer
discoveryManagerIntitializer
()
{
return
new
DiscoveryManagerInitializer
();
}
@Override
public
void
start
()
{
discoveryManagerIntitializer
().
init
();
new
Thread
(
new
Runnable
()
{
discoveryManagerIntitializer
().
init
();
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
try
{
new
EurekaBootStrap
()
{
@Override
protected
void
initEurekaEnvironment
()
{
try
{
if
(
System
.
getProperty
(
"log4j.configuration"
)
==
null
)
{
System
.
setProperty
(
"log4j.configuration"
,
new
ClassPathResource
(
"log4j.properties"
,
Log4JLoggingSystem
.
class
).
getURL
()
.
toString
());
}
}
catch
(
IOException
e
)
{
// ignore
}
LoggingConfiguration
.
getInstance
().
configure
();
EurekaServerConfigurationManager
.
getInstance
()
.
setConfiguration
(
eurekaServerConfig
);
XmlXStream
.
getInstance
().
setMarshallingStrategy
(
new
DataCenterAwareMarshallingStrategy
());
JsonXStream
.
getInstance
().
setMarshallingStrategy
(
new
DataCenterAwareMarshallingStrategy
());
XmlXStream
.
getInstance
().
setMarshallingStrategy
(
new
DataCenterAwareMarshallingStrategy
());
JsonXStream
.
getInstance
().
setMarshallingStrategy
(
new
DataCenterAwareMarshallingStrategy
());
// PeerAwareInstanceRegistry.getInstance();
applicationContext
.
publishEvent
(
new
EurekaRegistryAvailableEvent
(
...
...
@@ -229,12 +245,13 @@ public class EurekaServerInitializerConfiguration implements ServletContextAware
}
/**
* Additional aspect for intercepting method invocations on PeerAwareInstanceRegistry.
* If {@link PeerAwareInstanceRegistry#openForTraffic(int)} is called with a zero
* Additional aspect for intercepting method invocations on
* PeerAwareInstanceRegistry. If
* {@link PeerAwareInstanceRegistry#openForTraffic(int)} is called with a zero
* argument, it means that leases are not automatically cancelled if the instance
* hasn't sent any renewals recently. This happens for a standalone server. It
seems
*
like a bad default, so we set it to the smallest non-zero value we can, so that any
* instances that subsequently register can bump up the threshold.
* hasn't sent any renewals recently. This happens for a standalone server. It
*
seems like a bad default, so we set it to the smallest non-zero value we can,
*
so that any
instances that subsequently register can bump up the threshold.
*
* @author Dave Syer
*
...
...
@@ -246,7 +263,7 @@ public class EurekaServerInitializerConfiguration implements ServletContextAware
if
(
"openForTraffic"
.
equals
(
invocation
.
getMethod
().
getName
()))
{
int
count
=
(
int
)
invocation
.
getArguments
()[
0
];
ReflectionUtils
.
invokeMethod
(
invocation
.
getMethod
(),
invocation
.
getThis
(),
count
==
0
?
1
:
count
);
invocation
.
getThis
(),
count
==
0
?
1
:
count
);
return
null
;
}
return
invocation
.
proceed
();
...
...
spring-cloud-netflix-eureka-server/src/test/java/org/springframework/cloud/netflix/eureka/server/Log4JLoggingSystemTests.java
View file @
0f281bc9
...
...
@@ -50,8 +50,8 @@ public class Log4JLoggingSystemTests {
private
Logger
logger
;
@Before
public
void
setup
()
{
System
.
setProperty
(
"log4j.configuration"
,
getPackagedConfigFile
(
"log4j.properties"
));
public
void
setup
()
throws
IOException
{
System
.
setProperty
(
"log4j.configuration"
,
new
ClassPathResource
(
"log4j.properties"
,
Log4JLoggingSystem
.
class
).
getURL
().
toString
(
));
logger
=
Logger
.
getLogger
(
getClass
());
LoggingConfiguration
.
getInstance
().
configure
();
}
...
...
@@ -68,13 +68,4 @@ public class Log4JLoggingSystemTests {
equalTo
(
1
));
}
private
final
String
getPackagedConfigFile
(
String
fileName
)
{
try
{
return
new
ClassPathResource
(
fileName
,
Log4JLoggingSystem
.
class
).
getURL
().
toString
();
}
catch
(
IOException
e
)
{
throw
new
IllegalStateException
(
"Cannot create URL"
,
e
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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