Skip to content

Commit 22972da

Browse files
committed
Refactor to Spring Boot project
1 parent 92942cf commit 22972da

60 files changed

Lines changed: 130 additions & 615 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.gradle

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ apply plugin: 'java'
22
apply plugin: 'war'
33
apply plugin: 'idea'
44
apply plugin: 'eclipse'
5-
apply plugin: 'org.akhikhl.gretty'
6-
//apply plugin: 'spring-boot'
7-
5+
//apply plugin: 'org.akhikhl.gretty'
6+
apply plugin: 'spring-boot'
7+
//
88
// JDK 8
99
sourceCompatibility = 1.8
1010
targetCompatibility = 1.8
@@ -27,17 +27,24 @@ task warProduction(type: War){
2727

2828
dependencies {
2929
// spring boot
30-
compile("org.springframework.boot:spring-boot-starter-web")
30+
compile "org.springframework.boot:spring-boot-starter-web:1.3.0.M5"
31+
compile "org.springframework.boot:spring-boot-starter-jetty"
32+
compile "org.springframework.boot:spring-boot-starter-thymeleaf"
33+
compile "com.domingosuarez.boot:spring-boot-starter-jade4j:0.3.1"
34+
compile "org.springframework.boot:spring-boot-starter-redis"
35+
compile(group: 'org.springframework.boot', name: 'spring-boot-starter', version:'1.3.0.M5') {
36+
exclude(module: 'spring-boot-starter-logging')
37+
}
38+
compile 'org.springframework.boot:spring-boot-starter-log4j:1.3.0.M5'
39+
compile 'org.springframework.boot:spring-boot-starter-data-jpa:1.3.0.M5'
40+
compile 'org.springframework.boot:spring-boot-starter-security:1.3.0.M5'
3141

3242
// spring framework
3343
compile 'org.springframework:spring-context:4.2.1.RELEASE'
3444
compile 'org.springframework:spring-webmvc:4.1.7.RELEASE'
3545
compile 'org.springframework.security:spring-security-config:3.2.7.RELEASE'
3646
compile 'org.springframework.security:spring-security-web:3.2.7.RELEASE'
3747

38-
compile 'org.thymeleaf:thymeleaf-spring4:+'
39-
compile 'org.thymeleaf.extras:thymeleaf-extras-springsecurity3:+'
40-
4148
//persistence
4249
compile 'com.zaxxer:HikariCP:+'
4350
compile 'org.springframework:spring-orm:+'
@@ -99,10 +106,6 @@ dependencies {
99106
testCompile 'org.objenesis:objenesis:+'
100107
testCompile 'org.springframework:spring-test:+'
101108

102-
compile 'javax.servlet:jstl:1.2'
103-
104-
//include in compile only, exclude in the war
105-
providedCompile 'javax.servlet:servlet-api:2.5'
106109
}
107110

108111
//Gretty Embedded Jetty
@@ -130,8 +133,9 @@ buildscript {
130133
// Don't use Jetty8, even it's a servlet 3.0+ container,
131134
// but not support non-jar WebApplicationInitializer scanning.
132135
// It will cause "No Spring WebApplicationInitializer types detected on classpath"
133-
gretty {
134-
port = 8080
135-
contextPath = ''
136-
servletContainer = 'jetty9' //tomcat7 or tomcat8
137-
}
136+
// gretty {
137+
// port = 8080
138+
// contextPath = ''
139+
// servletContainer = 'jetty9' //tomcat7 or tomcat8
140+
// }
141+
//

deploy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def execute_cmds(ip, user, passwd, cmd):
3939
now = time.strftime("%Y%m%d%H%M%S")
4040
cmd = [
4141
'echo Stop jetty server... && service jetty stop',
42-
'echo Stop redis server... && service redis_6379 stop',
4342
'echo Flush all redis cache data... && redis-cli -r 1 flushall',
43+
'echo Stop redis server... && service redis_6379 stop',
4444
'echo Copy ' + new_war + ' to ' + war + \
4545
' && mv ' + war + ' ' + backup_dir + '/' + now + '-' + dist + \
4646
' && cp ' + new_war + ' ' + war ,

src/main/java/com/raysmond/blog/Application.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cache.annotation.EnableCaching;
6+
import org.springframework.context.annotation.ComponentScan;
57

68
/**
7-
* TODO use Spring Boot for running
9+
* @author Raysmond<jiankunlei@gmail.com>
810
*/
911
@SpringBootApplication
12+
@EnableCaching
1013
public class Application {
1114

1215
public static void main(String[] args) {
Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
11
package com.raysmond.blog;
22

33
/**
4-
* Constants class
5-
*
6-
* @author: Raysmond
4+
* @author: Raysmond<jiankunlei@gmail.com>
75
*/
86
public final class Constants {
97

10-
public static final String MESSAGE_SOURCE = "/i18n/messages";
8+
public static final String DEFAULT_ADMIN__EMAIL = "admin@admin.com";
119

12-
public static final String VIEWS = "/views/";
13-
14-
public static final String RESOURCES_LOCATION = "/resources/";
15-
16-
public static final String RESOURCES_HANDLER = RESOURCES_LOCATION + "**";
17-
18-
// Default super user email
19-
public static final String SUPER_USER_EMAIL = "admin@admin.com";
20-
21-
// Default super user password
22-
public static final String SUPER_USER_PASS = "admin";
10+
public static final String DEFAULT_ADMIN_PASSWORD = "admin";
2311

2412
public static final String ABOUT_PAGE_TITLE = "About";
13+
2514
}

src/main/java/com/raysmond/blog/config/JpaConfig.java renamed to src/main/java/com/raysmond/blog/JpaConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.raysmond.blog.config;
1+
package com.raysmond.blog;
22

33
import java.util.Properties;
44

src/main/java/com/raysmond/blog/config/SecurityConfig.java renamed to src/main/java/com/raysmond/blog/SecurityConfig.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
package com.raysmond.blog.config;
1+
package com.raysmond.blog;
22

33
import com.raysmond.blog.services.UserService;
44
import org.springframework.context.annotation.*;
55
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
66
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
77
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
8-
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
98
import org.springframework.security.crypto.password.PasswordEncoder;
109
import org.springframework.security.crypto.password.StandardPasswordEncoder;
1110
import org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices;
1211

1312
@Configuration
14-
@EnableWebMvcSecurity
15-
class SecurityConfig extends WebSecurityConfigurerAdapter {
13+
public class SecurityConfig extends WebSecurityConfigurerAdapter {
1614

1715
@Bean
1816
public UserService userService() {
@@ -41,10 +39,8 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {
4139
protected void configure(HttpSecurity http) throws Exception {
4240
http
4341
.authorizeRequests()
44-
.antMatchers("/admin","/admin/**").authenticated()
42+
.antMatchers("/admin/**").authenticated()
4543
.anyRequest().permitAll()
46-
//.antMatchers("/", "/favicon.ico", "/resources/**", "/webjars/**" , "/signup").permitAll()
47-
// .anyRequest().authenticated()
4844
.and()
4945
.formLogin()
5046
.loginPage("/signin")
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.raysmond.blog;
2+
3+
import com.raysmond.blog.support.web.ViewHelper;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.Configuration;
7+
import org.springframework.security.web.csrf.CsrfToken;
8+
import org.springframework.web.servlet.HandlerInterceptor;
9+
import org.springframework.web.servlet.ModelAndView;
10+
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
11+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
12+
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
13+
14+
import javax.servlet.http.HttpServletRequest;
15+
import javax.servlet.http.HttpServletResponse;
16+
17+
/**
18+
* @author Raysmond<jiankunlei@gmail.com>.
19+
*/
20+
@Configuration
21+
public class WebConfig extends WebMvcConfigurerAdapter {
22+
@Autowired
23+
private ViewHelper viewHelper;
24+
25+
@Override
26+
public void addInterceptors(InterceptorRegistry registry) {
27+
registry.addInterceptor(viewObjectAddingInterceptor());
28+
super.addInterceptors(registry);
29+
}
30+
31+
@Bean
32+
public HandlerInterceptor viewObjectAddingInterceptor() {
33+
return new HandlerInterceptorAdapter() {
34+
@Override
35+
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
36+
viewHelper.setStartTime(System.currentTimeMillis());
37+
38+
return true;
39+
}
40+
41+
@Override
42+
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView view) {
43+
CsrfToken token = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
44+
if (token != null) {
45+
// add csrf token
46+
view.addObject(token.getParameterName(), token);
47+
}
48+
49+
view.addObject("basePath", request.getContextPath());
50+
}
51+
};
52+
}
53+
}

src/main/java/com/raysmond/blog/admin/controllers/AdminController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.raysmond.blog.admin.controllers;
22

33
import com.raysmond.blog.forms.SettingsForm;
4-
import com.raysmond.blog.AppSetting;
4+
import com.raysmond.blog.services.AppSetting;
55
import com.raysmond.blog.support.web.MessageHelper;
66
import com.raysmond.blog.utils.DTOUtil;
77
import org.springframework.beans.factory.annotation.Autowired;

src/main/java/com/raysmond/blog/config/ApplicationConfig.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/main/java/com/raysmond/blog/config/CacheConfig.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)