Skip to content

Commit 5552578

Browse files
committed
Turned application into a Spring Boot application
1 parent 6bc0900 commit 5552578

16 files changed

Lines changed: 172 additions & 197 deletions

File tree

crypto-spring/pom.xml

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,70 +9,77 @@
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<artifactId>crypto-spring</artifactId>
12-
<packaging>war</packaging>
12+
<packaging>jar</packaging>
1313
<name>Crypto Spring</name>
1414

15-
<description>Spring project using encrypted properties with Jasypt sample project. Requires a server like Apache
16-
Tomcat or the Maven Tomcat7 plugin and a system property named APP_ENCRYPTION_PASSWORD (set automatically by
17-
the Tomcat7 plugin).
18-
19-
After launching, open the web application in your browser at http://localhost:8080/crypto-spring
15+
<description>Spring project using encrypted properties with Jasypt sample project. Start via the main method in the
16+
Application class. After launching, open the web application in your browser at http://localhost:8080.
2017
</description>
2118

19+
<properties>
20+
<start-class>de.dominikschadow.javasecurity.Application</start-class>
21+
</properties>
22+
2223
<dependencies>
2324
<dependency>
24-
<groupId>org.springframework</groupId>
25-
<artifactId>spring-webmvc</artifactId>
26-
</dependency>
27-
<dependency>
28-
<groupId>org.springframework</groupId>
29-
<artifactId>spring-jdbc</artifactId>
30-
</dependency>
31-
<dependency>
32-
<groupId>javax.servlet</groupId>
33-
<artifactId>javax.servlet-api</artifactId>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
3427
</dependency>
3528
<dependency>
36-
<groupId>javax.servlet.jsp</groupId>
37-
<artifactId>javax.servlet.jsp-api</artifactId>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-data-jpa</artifactId>
3831
</dependency>
3932
<dependency>
40-
<groupId>javax.servlet</groupId>
41-
<artifactId>jstl</artifactId>
33+
<groupId>org.webjars</groupId>
34+
<artifactId>bootstrap</artifactId>
4235
</dependency>
4336
<dependency>
44-
<groupId>org.jasypt</groupId>
45-
<artifactId>jasypt-spring31</artifactId>
37+
<groupId>org.webjars</groupId>
38+
<artifactId>webjars-locator</artifactId>
4639
</dependency>
4740
<dependency>
48-
<groupId>commons-dbcp</groupId>
49-
<artifactId>commons-dbcp</artifactId>
41+
<groupId>com.github.ulisesbocchio</groupId>
42+
<artifactId>jasypt-spring-boot-starter</artifactId>
5043
</dependency>
5144
<dependency>
5245
<groupId>com.h2database</groupId>
5346
<artifactId>h2</artifactId>
5447
</dependency>
55-
<dependency>
56-
<groupId>org.slf4j</groupId>
57-
<artifactId>slf4j-api</artifactId>
58-
</dependency>
59-
<dependency>
60-
<groupId>org.slf4j</groupId>
61-
<artifactId>slf4j-log4j12</artifactId>
62-
</dependency>
6348
</dependencies>
6449

6550
<build>
6651
<finalName>${project.artifactId}</finalName>
67-
<defaultGoal>tomcat7:run-war</defaultGoal>
52+
<defaultGoal>spring-boot:run</defaultGoal>
6853
<plugins>
6954
<plugin>
70-
<groupId>org.apache.tomcat.maven</groupId>
71-
<artifactId>tomcat7-maven-plugin</artifactId>
55+
<groupId>org.springframework.boot</groupId>
56+
<artifactId>spring-boot-maven-plugin</artifactId>
57+
<executions>
58+
<execution>
59+
<goals>
60+
<goal>build-info</goal>
61+
</goals>
62+
<configuration>
63+
<additionalProperties>
64+
<versions.spring-boot>${project.parent.parent.version}</versions.spring-boot>
65+
</additionalProperties>
66+
</configuration>
67+
</execution>
68+
</executions>
69+
</plugin>
70+
<plugin>
71+
<groupId>com.spotify</groupId>
72+
<artifactId>docker-maven-plugin</artifactId>
7273
<configuration>
73-
<systemProperties>
74-
<APP_ENCRYPTION_PASSWORD>spring-jasypt</APP_ENCRYPTION_PASSWORD>
75-
</systemProperties>
74+
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
75+
<dockerDirectory>src/main/docker</dockerDirectory>
76+
<resources>
77+
<resource>
78+
<targetPath>/</targetPath>
79+
<directory>${project.build.directory}</directory>
80+
<include>${project.build.finalName}.jar</include>
81+
</resource>
82+
</resources>
7683
</configuration>
7784
</plugin>
7885
</plugins>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM openjdk:8-jre-alpine
2+
MAINTAINER Dominik Schadow <dominikschadow@gmail.com>
3+
4+
VOLUME /tmp
5+
6+
ENV jasypt.encryptor.password spring-jasypt
7+
8+
ADD crypto-spring.jar app.jar
9+
10+
RUN sh -c 'touch /app.jar'
11+
12+
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "app.jar"]

crypto-spring/src/main/java/de/dominikschadow/javasecurity/spring/CryptoSpringWebAppInitializer.java renamed to crypto-spring/src/main/java/de/dominikschadow/javasecurity/Application.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,19 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
package de.dominikschadow.javasecurity.spring;
18+
package de.dominikschadow.javasecurity;
1919

20-
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
20+
import org.springframework.boot.SpringApplication;
21+
import org.springframework.boot.autoconfigure.SpringBootApplication;
2122

2223
/**
24+
* Starter class for the Spring Boot application.
25+
*
2326
* @author Dominik Schadow
2427
*/
25-
public class CryptoSpringWebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
26-
@Override
27-
protected Class<?>[] getRootConfigClasses() {
28-
return null;
29-
}
30-
31-
@Override
32-
protected Class<?>[] getServletConfigClasses() {
33-
return new Class[]{WebConfig.class};
34-
}
35-
36-
@Override
37-
protected String[] getServletMappings() {
38-
return new String[]{"/"};
28+
@SpringBootApplication
29+
public class Application {
30+
public static void main(String[] args) {
31+
SpringApplication.run(Application.class, args);
3932
}
4033
}

crypto-spring/src/main/java/de/dominikschadow/javasecurity/controller/IndexController.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,30 @@
1717
*/
1818
package de.dominikschadow.javasecurity.controller;
1919

20-
import org.springframework.beans.factory.annotation.Autowired;
21-
import org.springframework.jdbc.core.JdbcTemplate;
20+
import de.dominikschadow.javasecurity.domain.Greeting;
21+
import de.dominikschadow.javasecurity.domain.GreetingRepository;
2222
import org.springframework.stereotype.Controller;
2323
import org.springframework.ui.Model;
24+
import org.springframework.web.bind.annotation.GetMapping;
2425
import org.springframework.web.bind.annotation.RequestMapping;
2526

26-
import javax.sql.DataSource;
27-
28-
import static org.springframework.web.bind.annotation.RequestMethod.GET;
29-
3027
/**
31-
*
3228
* @author Dominik Schadow
3329
*/
3430
@Controller
35-
@RequestMapping(value = "/")
31+
@RequestMapping()
3632
public class IndexController {
37-
private JdbcTemplate jdbcTemplate;
33+
private final GreetingRepository greetingRepository;
3834

39-
@RequestMapping(method = GET)
35+
public IndexController(GreetingRepository greetingRepository) {
36+
this.greetingRepository = greetingRepository;
37+
}
38+
39+
@GetMapping
4040
public String index(Model model) {
41-
String greeting = jdbcTemplate.queryForObject("select greeting from greetings where greeting_id = 1", String.class);
41+
Greeting greeting = greetingRepository.findOne(1);
4242
model.addAttribute("greeting", greeting);
4343

4444
return "index";
4545
}
46-
47-
@Autowired
48-
public void setDataSource(DataSource dataSource) {
49-
jdbcTemplate = new JdbcTemplate(dataSource);
50-
}
5146
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (C) 2017 Dominik Schadow, dominikschadow@gmail.com
3+
*
4+
* This file is part of the Java Security project.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package de.dominikschadow.javasecurity.domain;
19+
20+
import javax.persistence.Column;
21+
import javax.persistence.Entity;
22+
import javax.persistence.Id;
23+
import javax.persistence.Table;
24+
25+
/**
26+
*
27+
* @author Dominik Schadow
28+
*/
29+
@Entity
30+
@Table(name = "greetings")
31+
public class Greeting {
32+
@Id
33+
@Column(name = "id")
34+
private int id;
35+
@Column(name = "greeting")
36+
private String greeting;
37+
38+
public int getId() {
39+
return id;
40+
}
41+
42+
public void setId(int id) {
43+
this.id = id;
44+
}
45+
46+
public String getGreeting() {
47+
return greeting;
48+
}
49+
50+
public void setGreeting(String greeting) {
51+
this.greeting = greeting;
52+
}
53+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package de.dominikschadow.javasecurity.domain;
2+
3+
import org.springframework.data.jpa.repository.JpaRepository;
4+
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
5+
6+
/**
7+
* Created by dos on 12.03.17.
8+
*/
9+
public interface GreetingRepository extends JpaRepository<Greeting, Integer>, JpaSpecificationExecutor {
10+
}

crypto-spring/src/main/java/de/dominikschadow/javasecurity/spring/WebConfig.java

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
spring.datasource.username=sampleUser
2+
spring.datasource.password=ENC(ic4OywKun/M1co/MSpJ7ybRcWIU9NZr/)
3+
#samplePassword

crypto-spring/src/main/resources/applicationContext.xml

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
insert into greetings (id, greeting) values (1, 'Hello, Spring Crypto with Jasypt Spring Boot Starter');

0 commit comments

Comments
 (0)