Skip to content

Commit

Permalink
重构一下启动测试类
Browse files Browse the repository at this point in the history
  • Loading branch information
Percy0601 committed Jun 19, 2015
1 parent 0120461 commit 071b944
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package boot.dubbo.infrastructure;
package boot;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

import boot.dubbo.infrastructure.ApplicationBootstrap;
import boot.ApplicationBootstrap;
import boot.dubbo.infrastructure.entity.User;
import boot.dubbo.infrastructure.repo.ComplexQueryRepo;
import boot.dubbo.infrastructure.repo.UserRepo;
Expand Down
16 changes: 15 additions & 1 deletion boot-dubbo-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>boot-dubbo-service</artifactId>
<packaging>jar</packaging>
<packaging>war</packaging>
<name>boot-dubbo-service Maven Webapp</name>
<url>http://maven.apache.org</url>

Expand All @@ -32,10 +32,24 @@
<artifactId>boot-dubbo-infrastructure</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package boot.dubbo.config;

//import org.springframework.boot.autoconfigure.SpringBootApplication;
//import org.springframework.context.annotation.ComponentScan;
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
//
//@SpringBootApplication
//@ComponentScan(basePackages = "boot")
//public class WebConfig extends WebMvcConfigurerAdapter {
//
//}
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@SpringBootApplication
@ComponentScan(basePackages = "boot")
public class WebConfig extends WebMvcConfigurerAdapter {

}
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
package boot.dubbo.starter;

//import javax.servlet.ServletContext;
//import javax.servlet.ServletException;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.autoconfigure.SpringBootApplication;
//import org.springframework.boot.builder.SpringApplicationBuilder;
//import org.springframework.boot.context.web.SpringBootServletInitializer;
//import org.springframework.context.annotation.ComponentScan;
//import org.springframework.core.env.Environment;

//@SpringBootApplication
//@ComponentScan(basePackages = "boot")
//public class SpringBootStarter extends SpringBootServletInitializer {
// private Logger log = LoggerFactory.getLogger(SpringBootStarter.class);
//
// @Autowired
// private Environment env;
//
// @Override
// protected SpringApplicationBuilder configure(
// SpringApplicationBuilder application) {
// log.info("=============容器启动(Spring Boot Container Start...)=============");
// return application.sources(WebConfig.class);
// }
//
// /**
// * Config ServletListener, ServletFilter
// */
// @Override
// public void onStartup(ServletContext servletContext)
// throws ServletException {
// log.info("+++++++++++++容器启动(Web Container Servetlet Start...)+++++++++++++");
// log.info("++++++++++++++++++++++++++{}" + (env == null));
//
// super.onStartup(servletContext);
// }
//
//}
import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;

import boot.dubbo.config.WebConfig;

@SpringBootApplication
@ComponentScan(basePackages = "boot")
public class SpringBootStarter extends SpringBootServletInitializer {
private Logger log = LoggerFactory.getLogger(SpringBootStarter.class);

@Autowired
private Environment env;

@Override
protected SpringApplicationBuilder configure(
SpringApplicationBuilder application) {
log.info("=============容器启动(Spring Boot Container Start...)=============");
return application.sources(WebConfig.class);
}

/**
* Config ServletListener, ServletFilter
*/
@Override
public void onStartup(ServletContext servletContext)
throws ServletException {
log.info("+++++++++++++容器启动(Web Container Servetlet Start...)+++++++++++++");
log.info("++++++++++++++++++++++++++{}" + (env == null));

super.onStartup(servletContext);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<!--<dubbo:service interface="boot.dubbo.api.UserService" ref="userService" protocol="rest"/>
<bean id="userService" class="boot.dubbo.service.UserServiceImpl" />-->

<dubbo:protocol name="rest" port="9090" threads="500" contextpath="services" server="netty" accepts="500"/>
<dubbo:protocol name="rest" port="9090" threads="500" contextpath="services" server="tomcat" accepts="500"/>
<dubbo:protocol name="dubbo" />
</beans>
4 changes: 2 additions & 2 deletions boot-dubbo-service/src/main/resources/dubbo.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ dubbo.container=log4j,spring
dubbo.application.name=demo-provider
dubbo.application.owner=percy
#dubbo.registry.address=multicast://224.5.6.7:1234
dubbo.registry.address=zookeeper://10.10.108.132:2181
dubbo.registry.address=zookeeper://10.10.108.222:2181
#dubbo.registry.address=redis://127.0.0.1:6379
#dubbo.registry.address=dubbo://127.0.0.1:9090
#dubbo.monitor.protocol=registry
dubbo.protocol.name=dubbo
dubbo.protocol.dubbo.port=20880
dubbo.protocol.name=rest
dubbo.protocol.rest.port=9090
dubbo.protocol.rest.server=netty
dubbo.protocol.rest.server=tomcat
dubbo.service.loadbalance=roundrobin
#dubbo.log4j.file=logs/dubbo-demo-consumer.log
#dubbo.log4j.level=WARN

0 comments on commit 071b944

Please sign in to comment.