Skip to content

Commit

Permalink
Polish alibaba#110 : remove application.properties and copy to META-I…
Browse files Browse the repository at this point in the history
…NF/nacos-default.properties
  • Loading branch information
mercyblitz committed Oct 2, 2018
1 parent 0ef461f commit 8a73c80
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 42 deletions.
3 changes: 0 additions & 3 deletions config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@
<directory>src/main/resources</directory>
<excludes>
<exclude>application.properties</exclude>
<exclude>banner.txt</exclude>
<exclude>schema.sql</exclude>
<exclude>nacos-db.sql</exclude>
</excludes>
</resource>
</resources>
Expand Down
17 changes: 0 additions & 17 deletions config/src/main/resources/application.properties

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# spring
management.security.enabled=false
server.contextPath=/nacos
server.servlet.contextPath=/nacos
server.port=8848
# Console Default Properties

spring.mvc.view.prefix=/jsp/
# 响应页面默认后缀
spring.mvc.view.suffix=.jsp
Expand Down
File renamed without changes.
17 changes: 14 additions & 3 deletions core/src/main/resources/META-INF/nacos-default.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# Nacos Default Properties

## Exclude Spring Boot Auto-Configuration class(es)
spring.autoconfigure.exclude=\
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
## Web Server
server.servlet.context-path=/nacos
server.port=8848
server.tomcat.uri-encoding=UTF-8

## HTTP Encoding
spring.http.encoding.force=true
spring.http.encoding.enabled=true

## i18n
spring.messages.encoding=UTF-8

## Exclude Spring Boot Auto-Configuration class(es)
spring.autoconfigure.exclude=\
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.env.CompositePropertySource;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.HashSet;

import static com.alibaba.nacos.core.env.NacosDefaultPropertySourceEnvironmentPostProcessor.PROPERTY_SOURCE_NAME;
import static com.alibaba.nacos.core.env.NacosDefaultPropertySourceEnvironmentPostProcessor.RESOURCE_LOCATION_PATTERN;
import static java.util.Arrays.asList;

/**
* {@link NacosDefaultPropertySourceEnvironmentPostProcessor} Test
Expand All @@ -48,10 +53,61 @@ public void testNacosDefaultPropertySourcePresent() {
// "nacos-default" must be present
Assert.assertTrue(propertySources.contains("nacos-default"));
// Get PropertySource via PROPERTY_SOURCE_NAME
PropertySource propertySource = propertySources.get(PROPERTY_SOURCE_NAME);
PropertySource propertySource = getNacosDefaultPropertySource();
// "nacos-default" must be present
Assert.assertNotNull(propertySource);
// make sure propertySource is last one
Assert.assertEquals(propertySources.size() - 1, propertySources.precedenceOf(propertySource));
}

@Test
public void testDefaultProperties() {

// Web Server
assertPropertyEquals("server.servlet.context-path", "/nacos");
assertPropertyEquals("server.port", "8848");
assertPropertyEquals("server.tomcat.uri-encoding", "UTF-8");

// HTTP Encoding
assertPropertyEquals("spring.http.encoding.force", "true");
assertPropertyEquals("spring.http.encoding.enabled", "true");

// i18n
assertPropertyEquals("spring.messages.encoding", "UTF-8");
}

@Test
public void testDefaultPropertyNames() {

assertPropertyNames(
"server.servlet.context-path",
"server.port",
"server.tomcat.uri-encoding",
"spring.http.encoding.force",
"spring.http.encoding.enabled",
"spring.messages.encoding",
"spring.autoconfigure.exclude"
);
}

private void assertPropertyNames(String... propertyNames) {

CompositePropertySource propertySource = getNacosDefaultPropertySource();

Assert.assertEquals("Please Properties from resources[" + RESOURCE_LOCATION_PATTERN + "]",
new HashSet<String>(asList(propertyNames)),
new HashSet<String>(asList(propertySource.getPropertyNames())));
}

private void assertPropertyEquals(String propertyName, String expectedValue) {
PropertySource propertySource = getNacosDefaultPropertySource();
Assert.assertEquals(expectedValue, propertySource.getProperty(propertyName));
}

private CompositePropertySource getNacosDefaultPropertySource() {
MutablePropertySources propertySources = environment.getPropertySources();
// Get PropertySource via PROPERTY_SOURCE_NAME
CompositePropertySource propertySource = (CompositePropertySource) propertySources.get(PROPERTY_SOURCE_NAME);
return propertySource;
}
}
2 changes: 1 addition & 1 deletion distribution/conf/application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# spring
management.security.enabled=false

server.contextPath=/nacos
server.servlet.contextPath=/nacos
server.port=8848
Expand Down
2 changes: 1 addition & 1 deletion distribution/conf/application.properties.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# spring
management.security.enabled=false

server.contextPath=/nacos
server.servlet.contextPath=/nacos
server.port=8848
Expand Down
9 changes: 9 additions & 0 deletions naming/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<excludes>
<exclude>application.properties</exclude>
</excludes>
</resource>
</resources>
</build>
<reporting>
<plugins>
Expand Down
10 changes: 0 additions & 10 deletions naming/src/main/resources/application.properties

This file was deleted.

2 changes: 1 addition & 1 deletion test/src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# spring
management.security.enabled=false

server.servlet.context-path=/nacos
server.port=8848

Expand Down

0 comments on commit 8a73c80

Please sign in to comment.