Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Calvin committed Dec 25, 2014
1 parent 6349135 commit e501181
Show file tree
Hide file tree
Showing 15 changed files with 272 additions and 149 deletions.
91 changes: 91 additions & 0 deletions examples/boot-more/note.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
Things not in demo

1. use applicactionContextxml

@ImportResource("applicationContext.xml")
public class BootServiceApplication {
}


2. use Jetty instead of Tomcat

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

3. disable web in junit test use spring context

setWebEnvironment(false)

4. set system exit code

org.springframework.boot.ExitCodeGenerator

5. read configuration
@Value(${name})
String name

or

@Autowired
Environment env;
env.get

6. set the configuration file path

java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties

or just change the file name

java -jar myproject.jar --spring.config.name=myproject

7. active profile
java -jar myproject.jar --spring.profiles.active=dev,hsqldb

SpringApplication.setAdditionalProfiles(…​)

8. define logging level in appliation.properties

logging.level.org.springframework.web: DEBUG
logging.level.org.hibernate: ERROR

9. add spring-mvc defenation
write WebMvcConfigurerAdapter without @EnableWebMvc

10. add servlet/filter

in application.properties

ServletRegistrationBean or FilterRegistrationBean

11. configure web

1. add context path
server.contextPath

2. set tomcat threads

12. JMX

1. add new jmx
@ManagedResource, @ManagedAttribute, @ManagedOperation

2. change jmx default domian name
endpoints.jmx.domain=myapp
endpoints.jmx.uniqueNames=true


13. APP id

14. Custom Health information
38 changes: 29 additions & 9 deletions examples/boot-more/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@

<properties>
<springside.version>4.3.0-SNAPSHOT</springside.version>
<spring-boot.version>1.1.8.RELEASE</spring-boot.version>
<spring-boot.version>1.1.10.RELEASE</spring-boot.version>
<commons-lang3.version>3.2.1</commons-lang3.version>
<javasimon.version>3.5.2</javasimon.version>
<assertj.version>1.7.0</assertj.version>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.6</java.version>
Expand All @@ -31,6 +34,17 @@
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
<exclusions>
<exclusion>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand Down Expand Up @@ -58,7 +72,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.2.1</version>
<version>${commons-lang3.version}</version>
</dependency>

<!-- jmx -->
Expand All @@ -67,6 +81,18 @@
<artifactId>jolokia-core</artifactId>
</dependency>

<!-- javasimon -->
<dependency>
<groupId>org.javasimon</groupId>
<artifactId>javasimon-spring</artifactId>
<version>${javasimon.version}</version>
</dependency>
<dependency>
<groupId>org.javasimon</groupId>
<artifactId>javasimon-console-embed</artifactId>
<version>${javasimon.version}</version>
</dependency>

<!-- test -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -77,7 +103,7 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>1.6.1</version>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>

Expand All @@ -90,12 +116,6 @@
</dependency>
</dependencies>

<profiles>
<profile>

</profile>
</profiles>

<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
@ComponentScan
// Spring Boot的AutoConfig
@EnableAutoConfiguration
public class BootServiceApplication {
public class BootMoreApplication {

public static void main(String[] args) throws Exception {
SpringApplication.run(BootServiceApplication.class, args);
SpringApplication.run(BootMoreApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.springside.examples.bootservice.common;

import org.javasimon.console.SimonConsoleServlet;
import org.javasimon.spring.MonitoredMeasuringPointcut;
import org.javasimon.spring.MonitoringInterceptor;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class JavaSimonConfig {

// 定义AOP
@Bean(name = "monitoringAdvisor")
public DefaultPointcutAdvisor monitoringAdvisor() {
DefaultPointcutAdvisor monitoringAdvisor = new DefaultPointcutAdvisor();
monitoringAdvisor.setAdvice(new MonitoringInterceptor());
monitoringAdvisor.setPointcut(new MonitoredMeasuringPointcut());
return monitoringAdvisor;
}

// 定义URL Mapping
@Bean
public ServletRegistrationBean dispatcherRegistration() {
ServletRegistrationBean registration = new ServletRegistrationBean(new SimonConsoleServlet());
registration.addInitParameter("url-prefix", "/javasimon");
registration.addUrlMappings("/javasimon/*");
return registration;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
spring.jpa.database=H2

spring.datasource.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:file:~/.h2/bootservice;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1;
spring.datasource.url=jdbc:h2:file:~/.h2/bootmore;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1;
spring.datasource.username=sa
spring.datasource.password=

Expand Down
4 changes: 2 additions & 2 deletions examples/boot-more/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ server.port=8080
management.port=7002

# logging
logging.file=/tmp/logs/bootservice.log
logging.file=/tmp/logs/bootmore.log

# pretty json format
http.mappers.json-pretty-print=true
Expand All @@ -23,5 +23,5 @@ endpoints.trace.enabled=false
#endpoints.shutdown.enabled=true

# /info endpoint
info.app.name=Spring Boot Web Service Example
info.app.name=More Spring Boot Web Service Example
info.app.version=${project.version}
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.client.RestTemplate;
import org.springside.examples.bootservice.BootServiceApplication;
import org.springside.examples.bootservice.BootMoreApplication;
import org.springside.examples.bootservice.domain.Task;
import org.springside.examples.bootservice.domain.User;
import org.springside.modules.test.data.RandomData;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = BootServiceApplication.class)
@SpringApplicationConfiguration(classes = BootMoreApplication.class)
@WebAppConfiguration
@IntegrationTest("server.port=0")
@DirtiesContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springside.examples.bootservice.BootServiceApplication;
import org.springside.examples.bootservice.BootMoreApplication;
import org.springside.examples.bootservice.domain.Task;
import org.springside.examples.bootservice.repository.TaskDao;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = BootServiceApplication.class)
@SpringApplicationConfiguration(classes = BootMoreApplication.class)
@DirtiesContext
public class TaskDaoTest {

@Autowired
Expand Down
14 changes: 9 additions & 5 deletions examples/boot-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

<properties>
<springside.version>4.3.0-SNAPSHOT</springside.version>
<spring-boot.version>1.1.8.RELEASE</spring-boot.version>

<spring-boot.version>1.1.10.RELEASE</spring-boot.version>
<commons-lang3.version>3.2.1</commons-lang3.version>
<assertj.version>1.7.0</assertj.version>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.6</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
Expand All @@ -25,6 +27,8 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand Down Expand Up @@ -52,7 +56,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.2.1</version>
<version>${commons-lang3.version}</version>
</dependency>

<!-- jmx -->
Expand All @@ -71,7 +75,7 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>1.6.1</version>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -101,7 +105,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<version>2.5</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springside.examples.bootservice.BootServiceApplication;
import org.springside.examples.bootservice.domain.Task;
import org.springside.examples.bootservice.repository.TaskDao;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = BootServiceApplication.class)
@DirtiesContext
public class TaskDaoTest {

@Autowired
Expand Down
Loading

0 comments on commit e501181

Please sign in to comment.