提交 047db465 编写于 作者: C Calvin

#29 Spring Profile配置升级,设定默认Profile为Production,functional...

#29  Spring Profile配置升级,设定默认Profile为Production,functional test通过改变环境变量而不是使用另一个web.xml来改变profile。独立出functional test的Profile。Maven只 执行refresh db时会读取重载过的application.local的属性。
上级 9652d439
......@@ -311,11 +311,11 @@
</build>
<profiles>
<!-- 仅执行smoke test-->
<profile>
<id>smoke-test</id>
<build>
<plugins>
<!-- 仅执行smoke test-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
......@@ -330,11 +330,11 @@
</build>
</profile>
<!-- 执行所有functional test-->
<profile>
<id>integration-test</id>
<build>
<plugins>
<!-- 执行所有functional test-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
......@@ -348,6 +348,7 @@
</build>
</profile>
<!-- 刷新新开发环境数据库 -->
<profile>
<id>refresh-db</id>
<build>
......@@ -357,6 +358,7 @@
<artifactId>maven-antrun-plugin</artifactId>
<configuration>
<target>
<property file="src/main/resources/application.local.properties" />
<property file="src/main/resources/application.properties" />
<property name="sql.type" value="h2" />
......
......@@ -32,6 +32,7 @@
<!-- JSR303 Validator定义 -->
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
<!-- production/local development环境 -->
<beans profile="production">
<!-- 定义易受环境影响的变量 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
......@@ -44,7 +45,7 @@
<!-- 本地开发环境配置 -->
<value>classpath*:/application.local.properties</value>
<!-- 服务器生产环境配置 -->
<value>file:/var/mini-service/application.server.properties</value>
<!-- <value>file:/opt/mini-service/application.server.properties</value> -->
</list>
</property>
</bean>
......@@ -70,6 +71,7 @@
<!--<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/ExampleDB" />-->
</beans>
<!-- unit test环境 -->
<beans profile="test">
<!-- 定义易受环境影响的变量 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
......@@ -79,16 +81,13 @@
<list>
<!-- 标准配置 -->
<value>classpath*:/application.properties</value>
<!-- 本地开发环境配置 -->
<value>classpath*:/application.local.properties</value>
<!-- 测试环境配置 -->
<value>classpath*:/application.test.properties</value>
<!-- 本地测试环境配置 -->
<value>classpath*:/application.test-local.properties</value>
</list>
</property>
</bean>
</bean>
<!-- 非Pool的简单data source -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<!-- Connection Info -->
<property name="driverClass" value="${jdbc.driver}" />
......@@ -97,16 +96,49 @@
<property name="password" value="${jdbc.password}" />
</bean>
<!-- 初始化数据结构 -->
<jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
<jdbc:script location="classpath:sql/h2/schema.sql" />
</jdbc:initialize-database>
<!-- 初始化默认数据 -->
<bean class="org.springside.modules.test.data.DefaultDataInitializer" lazy-init="false">
<property name="dataSource" ref="dataSource"/>
<property name="defaultDataFile" value="/data/sample-data.xml" />
</bean>
<!-- 以静态变量保存ApplicationContext -->
<bean class="org.springside.modules.test.spring.SpringContextHolder" lazy-init="false" />
</beans>
<!-- functional test环境 -->
<beans profile="functional">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<!-- 标准配置 -->
<value>classpath*:/application.properties</value>
<!-- 本地标准配置 -->
<value>classpath*:/application.local.properties</value>
<!-- 测试环境配置 -->
<value>classpath*:/application.functional.properties</value>
<!-- 本地测试环境配置 -->
<value>classpath*:/application.functional-local.properties</value>
</list>
</property>
</bean>
<!-- 非Pool的简单data source -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<!-- Connection Info -->
<property name="driverClass" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!-- 初始化数据结构 -->
<jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
<jdbc:script location="classpath:sql/h2/schema.sql" />
</jdbc:initialize-database>
</beans>
</beans>
\ No newline at end of file
......@@ -15,9 +15,9 @@
</param-value>
</context-param>
<!-- 設定Spring Context的Profile -->
<!-- 設定Spring Context的默认Profile -->
<context-param>
<param-name>spring.profiles.active</param-name>
<param-name>spring.profiles.default</param-name>
<param-value>production</param-value>
</context-param>
......
......@@ -30,8 +30,9 @@ public class BaseFunctionalTestCase {
protected static SimpleDriverDataSource dataSource;
protected static PropertiesLoader propertiesLoader = new PropertiesLoader(
"classpath:/application.functional.properties", "classpath:/application.functional-local.properties");
protected static PropertiesLoader propertiesLoader = new PropertiesLoader("classpath:/application.properties",
"classpath:/application.local.properties", "classpath:/application.functional.properties",
"classpath:/application.functional-local.properties");
private static Logger logger = LoggerFactory.getLogger(BaseFunctionalTestCase.class);
......@@ -54,8 +55,10 @@ public class BaseFunctionalTestCase {
*/
protected static void startJettyOnce() throws Exception {
if (jettyServer == null) {
jettyServer = JettyFactory.createServer(new URL(baseUrl).getPort(), Start.CONTEXT,
"src/test/resources/web.xml");
//设定Spring的profile
System.setProperty("spring.profiles.active", "functional");
jettyServer = JettyFactory.createServer(new URL(baseUrl).getPort(), Start.CONTEXT);
jettyServer.start();
logger.info("Jetty Server started");
......
baseUrl=http://localhost:8084/mini-service
embedded=true
jdbc.driver=org.h2.Driver
jdbc.url=jdbc:h2:mem:mini-service4;DB_CLOSE_DELAY=-1
jdbc.username=sa
jdbc.password=
embedded=true
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>mini-service</display-name>
<!-- Spring ApplicationContext配置文件的路径,可使用通配符,多个路径用,号分隔 此参数用于后面的Spring Context Loader -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:/applicationContext.xml
classpath*:/applicationContext-rs-server.xml
classpath*:/applicationContext-ws-server.xml
</param-value>
</context-param>
<!-- 設定Spring Context的Profile -->
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>test</param-value>
</context-param>
<!--Spring ApplicationContext 载入 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- CXF 配置 -->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>
<!-- Jersey 配置 -->
<servlet>
<servlet-name>JerseyServlet</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
<!-- 使用Jackson for JSON格式 -->
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>JerseyServlet</servlet-name>
<url-pattern>/rs/*</url-pattern>
</servlet-mapping>
</web-app>
......@@ -319,11 +319,11 @@
</build>
<profiles>
<!-- 仅执行smoke test-->
<profile>
<id>smoke-test</id>
<build>
<plugins>
<!-- 仅执行smoke test-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
......@@ -341,12 +341,12 @@
</plugins>
</build>
</profile>
<!-- 执行所有functional test-->
<profile>
<id>integration-test</id>
<build>
<plugins>
<!-- 执行所有functional test-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
......@@ -363,7 +363,8 @@
</plugins>
</build>
</profile>
<!-- 刷新开发环境数据库 -->
<profile>
<id>refresh-db</id>
<build>
......@@ -373,7 +374,8 @@
<artifactId>maven-antrun-plugin</artifactId>
<configuration>
<target>
<property file="src/main/resources/application.properties" />
<property file="src/main/resources/application.local.properties" />
<property file="src/main/resources/application.properties" />
<property name="sql.type" value="h2" />
<property name="dbunit.datatype" value="org.dbunit.ext.h2.H2DataTypeFactory" />
......
......@@ -48,8 +48,9 @@
<!-- 使用annotation定义事务 -->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
<beans profile="production">
<!-- 定义受环境影响易变的变量 -->
<!-- production/local development环境 -->
<beans profile="production">
<!-- 定义易受环境影响的变量 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreResourceNotFound" value="true" />
......@@ -60,32 +61,35 @@
<!-- 本地开发环境配置 -->
<value>classpath*:/application.local.properties</value>
<!-- 服务器生产环境配置 -->
<value>file:/var/mini-web/application.server.properties</value>
<!-- <value>file:/opt/mini-service/application.server.properties</value> -->
</list>
</property>
</bean>
<!-- 数据源配置,使用应用内的DBCP数据库连接池 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" lazy-init="false">
<!-- 数据源配置, 使用应用中的DBCP数据库连接池 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<!-- Connection Info -->
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<!-- Connection Pooling Info -->
<property name="maxIdle" value="${dbcp.maxIdle}" />
<property name="maxActive" value="${dbcp.maxActive}" />
<property name="maxIdle" value="${dbcp.maxIdle}" />
<property name="defaultAutoCommit" value="false" />
<!-- 连接Idle一个小时后超时 -->
<property name="timeBetweenEvictionRunsMillis" value="3600000" />
<property name="minEvictableIdleTimeMillis" value="3600000" />
</bean>
<!-- 数据源配置,使用应用服务器的数据库连接池 -->
<!--<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/ExampleDB" />-->
</beans>
<!-- unit test环境 -->
<beans profile="test">
<!-- 定义易受环境影响的变量 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreResourceNotFound" value="true" />
......@@ -93,18 +97,15 @@
<list>
<!-- 标准配置 -->
<value>classpath*:/application.properties</value>
<!-- 本地开发环境配置 -->
<value>classpath*:/application.local.properties</value>
<!-- 测试环境配置 -->
<value>classpath*:/application.test.properties</value>
<!-- 本地测试环境配置 -->
<value>classpath*:/application.test-local.properties</value>
</list>
</property>
</bean>
</bean>
<!-- 非Pool的简单data source -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<!-- Connection Info -->
<property name="driverClass" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
......@@ -115,13 +116,45 @@
<jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
<jdbc:script location="classpath:sql/h2/schema.sql" />
</jdbc:initialize-database>
<!-- 初始化默认数据 -->
<bean class="org.springside.modules.test.data.DefaultDataInitializer" lazy-init="false">
<property name="dataSource" ref="dataSource"/>
<property name="defaultDataFile" value="/data/sample-data.xml" />
</bean>
</beans>
<!-- functional test环境 -->
<beans profile="functional">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<!-- 标准配置 -->
<value>classpath*:/application.properties</value>
<!-- 本地标准配置 -->
<value>classpath*:/application.local.properties</value>
<!-- 测试环境配置 -->
<value>classpath*:/application.functional.properties</value>
<!-- 本地测试环境配置 -->
<value>classpath*:/application.functional-local.properties</value>
</list>
</property>
</bean>
<!-- 非Pool的简单data source -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<!-- Connection Info -->
<property name="driverClass" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!-- 以静态变量保存ApplicationContext -->
<bean class="org.springside.modules.test.spring.SpringContextHolder" lazy-init="false" />
<!-- 初始化数据结构 -->
<jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
<jdbc:script location="classpath:sql/h2/schema.sql" />
</jdbc:initialize-database>
</beans>
</beans>
\ No newline at end of file
......@@ -15,9 +15,9 @@
</param-value>
</context-param>
<!-- 設定Spring Context的Profile -->
<!-- 設定Spring Context的默认Profile -->
<context-param>
<param-name>spring.profiles.active</param-name>
<param-name>spring.profiles.default</param-name>
<param-value>production</param-value>
</context-param>
......
......@@ -39,8 +39,9 @@ public class BaseFunctionalTestCase {
protected static Selenium2 s;
protected static PropertiesLoader propertiesLoader = new PropertiesLoader(
"classpath:/application.functional.properties", "classpath:/application.functional-local.properties");
protected static PropertiesLoader propertiesLoader = new PropertiesLoader("classpath:/application.properties",
"classpath:/application.local.properties", "classpath:/application.functional.properties",
"classpath:/application.functional-local.properties");
private static Logger logger = LoggerFactory.getLogger(BaseFunctionalTestCase.class);
......@@ -72,8 +73,10 @@ public class BaseFunctionalTestCase {
*/
protected static void startJettyOnce() throws Exception {
if (jettyServer == null) {
jettyServer = JettyFactory.createServer(new URL(baseUrl).getPort(), Start.CONTEXT,
"src/test/resources/web.xml");
//设定Spring的profile
System.setProperty("spring.profiles.active", "functional");
jettyServer = JettyFactory.createServer(new URL(baseUrl).getPort(), Start.CONTEXT);
jettyServer.start();
logger.info("Jetty Server started");
......
baseUrl=http://localhost:8082/mini-web
embedded=true
jdbc.driver=org.h2.Driver
jdbc.url=jdbc:h2:mem:mini-web4;DB_CLOSE_DELAY=-1
jdbc.username=sa
jdbc.password=
#selenium settings, options include firefox,ie,chrome,remote:localhost:4444:firefox
selenium.driver=firefox
\ No newline at end of file
selenium.driver=firefox
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>mini-web</display-name>
<!-- Spring ApplicationContext配置文件的路径,可使用通配符,多个路径用,号分隔
此参数用于后面的Spring Context Loader -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:/applicationContext.xml
classpath*:/applicationContext-shiro.xml
</param-value>
</context-param>
<!-- 設定Spring Context的Profile -->
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>test</param-value>
</context-param>
<!-- Filter 定义 -->
<!-- Character Encoding filter -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Open Entity Manager in View filter-->
<filter>
<filter-name>openEntityManagerInViewFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openEntityManagerInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Shiro Security filter-->
<filter>
<filter-name>shiroFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Sitemesh filter -->
<filter>
<filter-name>sitemeshFilter</filter-name>
<filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemeshFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring MVC Servlet -->
<servlet>
<servlet-name>springServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!--Spring的ApplicationContext 载入 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- session超时定义,单位为分钟 -->
<session-config>
<session-timeout>20</session-timeout>
</session-config>
<!-- 出错页面定义 -->
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/WEB-INF/views/error/500.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/views/error/500.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/views/error/404.jsp</location>
</error-page>
</web-app>
......@@ -476,11 +476,11 @@
</build>
<profiles>
<!-- 仅执行smoke test -->
<profile>
<id>smoke-test</id>
<build>
<plugins>
<!-- 仅执行smoke test -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
......@@ -499,11 +499,11 @@
</build>
</profile>
<!-- 执行所有functional test -->
<profile>
<id>integration-test</id>
<build>
<plugins>
<!-- 执行所有functional test -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
......@@ -521,6 +521,7 @@
</build>
</profile>
<!-- 刷新开发环境数据库 -->
<profile>
<id>refresh-db</id>
<build>
......@@ -530,6 +531,7 @@
<artifactId>maven-antrun-plugin</artifactId>
<configuration>
<target>
<property file="src/main/resources/application.local.properties" />
<property file="src/main/resources/application.properties" />
<property name="sql.type" value="h2" />
......
......@@ -58,6 +58,7 @@
<!-- hibernat validator -->
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
<!-- production/local development环境 -->
<beans profile="production">
<!-- 定义受环境影响易变的变量 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
......@@ -70,7 +71,7 @@
<!-- 本地开发环境配置 -->
<value>classpath*:/application.local.properties</value>
<!-- 服务器生产环境配置 -->
<value>file:/opt/springside/showcase/application.server.properties</value>
<!-- <value>file:/opt/springside/showcase/application.server.properties</value> -->
</list>
</property>
</bean>
......@@ -94,6 +95,7 @@
</bean>
</beans>
<!-- unit test环境 -->
<beans profile="test">
<!-- 定义受环境影响易变的变量 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
......@@ -103,17 +105,13 @@
<list>
<!-- 标准配置 -->
<value>classpath*:/application.properties</value>
<!-- 本地开发环境配置 -->
<value>classpath*:/application.local.properties</value>
<!-- 测试环境配置 -->
<value>classpath*:/application.test.properties</value>
<!-- 本地测试环境配置 -->
<value>classpath*:/application.test-local.properties</value>
</list>
</property>
</bean>
<!-- 数据源配置,在测试环境使用JDBC直接连接 -->
<!-- 非Pool的简单data source -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<!-- Connection Info -->
<property name="driverClass" value="${jdbc.driver}" />
......@@ -129,23 +127,66 @@
<property name="password" value="${quartz.jdbc.password}" />
</bean>
<!-- 运行脚本初始化内存数据库 -->
<!-- 初始化数据结构 -->
<jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
<jdbc:script location="classpath:sql/h2/schema.sql" />
</jdbc:initialize-database>
<!-- 运行脚本初始化内存数据库 -->
<!-- 初始化数据结构 -->
<jdbc:initialize-database data-source="quartzDataSource" ignore-failures="ALL">
<jdbc:script location="classpath:sql/h2/quartz.sql" />
</jdbc:initialize-database>
<!-- 初始化默认数据 -->
<bean class="org.springside.modules.test.data.DefaultDataInitializer" lazy-init="false">
<property name="dataSource" ref="dataSource"/>
<property name="defaultDataFile" value="/data/sample-data.xml" />
</bean>
<!-- SpringContextHolder定义 -->
<bean class="org.springside.modules.test.spring.SpringContextHolder" lazy-init="false" />
</beans>
<!-- functional test环境 -->
<beans profile="functional">
<!-- 定义受环境影响易变的变量 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<!-- 标准配置 -->
<value>classpath*:/application.properties</value>
<!-- 本地标准配置 -->
<value>classpath*:/application.local.properties</value>
<!-- 测试环境配置 -->
<value>classpath*:/application.functional.properties</value>
<!-- 本地测试环境配置 -->
<value>classpath*:/application.functional-local.properties</value>
</list>
</property>
</bean>
<!-- 非Pool的简单data source -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<!-- Connection Info -->
<property name="driverClass" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="quartzDataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<property name="driverClass" value="${quartz.jdbc.driver}" />
<property name="url" value="${quartz.jdbc.url}" />
<property name="username" value="${quartz.jdbc.username}" />
<property name="password" value="${quartz.jdbc.password}" />
</bean>
<!-- 初始化数据结构 -->
<jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
<jdbc:script location="classpath:sql/h2/schema.sql" />
</jdbc:initialize-database>
<!-- 初始化数据结构 -->
<jdbc:initialize-database data-source="quartzDataSource" ignore-failures="ALL">
<jdbc:script location="classpath:sql/h2/quartz.sql" />
</jdbc:initialize-database>
</beans>
</beans>
\ No newline at end of file
......@@ -14,9 +14,9 @@
</param-value>
</context-param>
<!-- 設定Spring Context的Profile -->
<!-- 設定Spring Context的默认Profile -->
<context-param>
<param-name>spring.profiles.active</param-name>
<param-name>spring.profiles.default</param-name>
<param-value>production</param-value>
</context-param>
......
......@@ -28,8 +28,9 @@ public class BaseFunctionalTestCase {
protected static SimpleDriverDataSource dataSource;
protected static PropertiesLoader propertiesLoader = new PropertiesLoader(
"classpath:/application.functional.properties", "classpath:/application.functional-local.properties");
protected static PropertiesLoader propertiesLoader = new PropertiesLoader("classpath:/application.properties",
"classpath:/application.local.properties", "classpath:/application.functional.properties",
"classpath:/application.functional-local.properties");
private static Logger logger = LoggerFactory.getLogger(BaseFunctionalTestCase.class);
......@@ -52,8 +53,10 @@ public class BaseFunctionalTestCase {
*/
protected static void startJettyOnce() throws Exception {
if (jettyServer == null) {
jettyServer = JettyFactory.createServer(new URL(baseUrl).getPort(), Start.CONTEXT,
"src/test/resources/web.xml");
//设定Spring的profile
System.setProperty("spring.profiles.active", "functional");
jettyServer = JettyFactory.createServer(new URL(baseUrl).getPort(), Start.CONTEXT);
jettyServer.start();
logger.info("Jetty Server started");
......
baseUrl=http://localhost:8083/showcase
embedded=true
jdbc.driver=org.h2.Driver
jdbc.url=jdbc:h2:mem:showcase4;DB_CLOSE_DELAY=-1
jdbc.username=sa
jdbc.password=
#selenium settings, options include firefox,ie,chrome,htmlunit,remote:localhost:4444:firefox
selenium.driver=firefox
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>showcase</display-name>
<!-- Spring ApplicationContext配置文件的路径,可使用通配符,用于后面的Spring Context Loader -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:/applicationContext.xml
classpath*:/applicationContext-showcases.xml
</param-value>
</context-param>
<!-- 設定Spring Context的Profile -->
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>test</param-value>
</context-param>
<!--Spring ApplicationContext 载入 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Spring MVC Servlet -->
<servlet>
<servlet-name>springServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- Jersey Servlet 配置 -->
<servlet>
<servlet-name>JerseyServlet</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
<!-- 使用Jackson for JSON格式 -->
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>JerseyServlet</servlet-name>
<url-pattern>/rs/*</url-pattern>
</servlet-mapping>
<!-- Content Servlet 配置 -->
<servlet>
<servlet-name>StaticContentServlet</servlet-name>
<servlet-class>org.springside.examples.showcase.web.StaticContentServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>StaticContentServlet</servlet-name>
<url-pattern>/static-content</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>RemoteContentServlet</servlet-name>
<servlet-class>org.springside.examples.showcase.web.RemoteContentServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RemoteContentServlet</servlet-name>
<url-pattern>/remote-content</url-pattern>
</servlet-mapping>
<!-- Filter 定义 -->
<!-- Character Encoding filter -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<!-- Open Entity Manager in View filter-->
<filter>
<filter-name>openEntityManagerInViewFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openEntityManagerInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Shiro filter -->
<filter>
<filter-name>shiroFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<!-- Cache Control Header Filter -->
<filter>
<filter-name>cacheControlHeaderFilter</filter-name>
<filter-class>org.springside.examples.showcase.web.CacheControlHeaderFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>cacheControlHeaderFilter</filter-name>
<url-pattern>/static/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>sitemeshFilter</filter-name>
<filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemeshFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 出错页面定义 -->
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/WEB-INF/views/error/500.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/views/error/500.jsp</location>
</error-page>
</web-app>
......@@ -31,13 +31,4 @@ public class JettyFactory {
return server;
}
/**
* 创建Jetty Server,以 以src/main/webapp为Web应用目录并重新制定web.xml路径。
*/
public static Server createServer(int port, String contextPath, String webxmlPath) {
Server server = createServer(port, contextPath);
((WebAppContext) server.getHandler()).setDescriptor(webxmlPath);
return server;
}
}
......@@ -19,7 +19,7 @@ public class JettyFactoryTest {
@Test
public void createTestServer() {
Server server = JettyFactory.createServer(1978, "core", "src/test/resources/web.xml");
Server server = JettyFactory.createServer(1978, "core");
assertEquals(1978, server.getConnectors()[0].getPort());
assertEquals("core", ((WebAppContext) server.getHandler()).getContextPath());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册