Skip to content

Commit a2b9a2b

Browse files
Spring Boot Issue #402
* Now includes Thymeleaf Starter * FetchBikingPicturesJob not instantiated without valid api token
1 parent a7283f2 commit a2b9a2b

File tree

5 files changed

+22
-45
lines changed

5 files changed

+22
-45
lines changed

pom.xml

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>eu.michael-simons</groupId>
77
<artifactId>biking2</artifactId>
8-
<version>0.2.5-SNAPSHOT</version>
8+
<version>0.2.6-SNAPSHOT</version>
99

1010
<parent>
1111
<groupId>org.springframework.boot</groupId>
@@ -137,6 +137,16 @@
137137
<groupId>org.springframework.boot</groupId>
138138
<artifactId>spring-boot-starter-web</artifactId>
139139
</dependency>
140+
<dependency>
141+
<groupId>org.springframework.boot</groupId>
142+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
143+
<exclusions>
144+
<exclusion>
145+
<groupId>org.javassist</groupId>
146+
<artifactId>javassist</artifactId>
147+
</exclusion>
148+
</exclusions>
149+
</dependency>
140150
<dependency>
141151
<groupId>org.springframework</groupId>
142152
<artifactId>spring-orm</artifactId>
@@ -258,21 +268,7 @@
258268
<groupId>org.webjars</groupId>
259269
<artifactId>openlayers</artifactId>
260270
<version>${openlayers.version}</version>
261-
</dependency>
262-
<dependency>
263-
<groupId>org.thymeleaf</groupId>
264-
<artifactId>thymeleaf</artifactId>
265-
<exclusions>
266-
<exclusion>
267-
<groupId>org.javassist</groupId>
268-
<artifactId>javassist</artifactId>
269-
</exclusion>
270-
</exclusions>
271-
</dependency>
272-
<dependency>
273-
<groupId>org.thymeleaf</groupId>
274-
<artifactId>thymeleaf-spring4</artifactId>
275-
</dependency>
271+
</dependency>
276272

277273
<dependency>
278274
<groupId>org.hamcrest</groupId>

src/main/java/ac/simons/biking2/config/WebConfig.java

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,19 @@
2222
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
2323
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule.Priority;
2424
import java.util.EnumSet;
25-
import java.util.Set;
2625
import javax.servlet.DispatcherType;
2726
import javax.servlet.MultipartConfigElement;
28-
import javax.servlet.ServletContainerInitializer;
2927
import javax.servlet.ServletContext;
30-
import javax.servlet.ServletException;
3128
import org.springframework.beans.BeansException;
3229
import org.springframework.beans.factory.annotation.Value;
3330
import org.springframework.beans.factory.config.BeanPostProcessor;
31+
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
3432
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainerFactory;
3533
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
3634
import org.springframework.boot.context.embedded.ServletContextInitializer;
3735
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
3836
import org.springframework.context.annotation.Bean;
39-
import org.springframework.context.annotation.Condition;
40-
import org.springframework.context.annotation.ConditionContext;
41-
import org.springframework.context.annotation.Conditional;
4237
import org.springframework.context.annotation.Configuration;
43-
import org.springframework.core.env.Environment;
44-
import org.springframework.core.type.AnnotatedTypeMetadata;
4538
import org.springframework.stereotype.Controller;
4639
import org.springframework.web.bind.annotation.RequestMapping;
4740
import org.springframework.web.filter.CharacterEncodingFilter;
@@ -82,7 +75,6 @@ public ServletContextInitializer servletContextInitializer() {
8275
characterEncodingFilter.setEncoding("UTF-8");
8376
characterEncodingFilter.setForceEncoding(false);
8477

85-
// TODO Blog
8678
servletContext.addFilter("characterEncodingFilter", characterEncodingFilter).addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*");
8779
};
8880
}
@@ -146,22 +138,8 @@ public ObjectMapper jacksonObjectMapper() {
146138
);
147139
}
148140

149-
// TODO Blog
150-
/**
151-
* This is a condition based on a property. If the property is set and not
152-
* empty, the EmbeddedServletContainer needs a customized connector
153-
*/
154-
static class NeedsCustomizedConnectorCondition implements Condition {
155-
156-
@Override
157-
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
158-
final Environment environment = context.getEnvironment();
159-
return environment.containsProperty("biking2.connector.proxyName") && !environment.getProperty("biking2.connector.proxyName", String.class).isEmpty();
160-
}
161-
}
162-
163141
@Bean
164-
@Conditional(NeedsCustomizedConnectorCondition.class)
142+
@ConditionalOnExpression(value = "environment['biking2.connector.proxyName'] != null && !environment['biking2.connector.proxyName'].isEmpty()")
165143
public EmbeddedServletContainerCustomizer embeddedServletContainerCustomizer(
166144
final @Value("${biking2.connector.proxyName}") String proxyName,
167145
final @Value("${biking2.connector.proxyPort:80}") int proxyPort

src/main/java/ac/simons/biking2/jobs/DailyFratzeProvider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@
2424
import java.util.logging.Logger;
2525
import org.springframework.beans.factory.annotation.Autowired;
2626
import org.springframework.beans.factory.annotation.Value;
27+
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
2728
import org.springframework.stereotype.Component;
2829

2930
/**
3031
* @author Michael J. Simons, 2014-02-18
3132
*/
3233
@Component
34+
@ConditionalOnExpression(value = "environment['biking2.dailyfratze-access-token'] != null && !environment['biking2.dailyfratze-access-token'].isEmpty()")
3335
public class DailyFratzeProvider {
3436
private final String accessToken;
3537

3638
@Autowired
37-
public DailyFratzeProvider(final @Value("${biking2.dailyfratze-access-token:na}") String accessToken) {
39+
public DailyFratzeProvider(final @Value("${biking2.dailyfratze-access-token}") String accessToken) {
3840
this.accessToken = accessToken;
3941
}
4042

src/main/java/ac/simons/biking2/jobs/FetchBikingPicturesJob.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import javax.xml.bind.JAXBException;
3737
import javax.xml.bind.Unmarshaller;
3838
import org.springframework.beans.factory.annotation.Autowired;
39+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
40+
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
3941
import org.springframework.context.annotation.Profile;
4042
import org.springframework.scheduling.annotation.Scheduled;
4143
import org.springframework.stereotype.Component;
@@ -48,8 +50,9 @@
4850
*/
4951
@Component
5052
@Profile({"dev", "prod"})
53+
@ConditionalOnBean(DailyFratzeProvider.class)
5154
public class FetchBikingPicturesJob {
52-
55+
5356
private final DailyFratzeProvider dailyFratzeProvider;
5457
private final BikingPictureRepository bikingPictureRepository;
5558
private final File bikingPicturesStorage;

src/main/resources/application.properties

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,4 @@ security.user.password = biking2
2323
biking2.home.longitude = 6.179489185520004
2424
biking2.home.latitude = 50.75144902272457
2525

26-
spring.thymeleaf.cache = false
27-
spring.thymeleaf.prefix = classpath:templates/
28-
spring.thymeleaf.suffix = .html
26+
spring.thymeleaf.cache = false

0 commit comments

Comments
 (0)