Skip to content

Commit 01573e4

Browse files
committed
refactor: move inclusion of image_dao_queries.properties to the appropriate package config
We also switched to using Environment.getRequiredProperty() because @value doesn't work without PropertySourcesPlaceholderConfigurer bean (that we are going to remove soon). Relate to #927
1 parent 291265c commit 01573e4

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

src/main/java/ru/mystamps/web/config/ApplicationContext.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public static PropertySourcesPlaceholderConfigurer getPropertySourcesPlaceholder
4343
PropertySourcesPlaceholderConfigurer configurer =
4444
new PropertySourcesPlaceholderConfigurer();
4545
configurer.setLocations(
46-
new ClassPathResource("sql/image_dao_queries.properties"),
4746
new ClassPathResource("sql/user_dao_queries.properties"),
4847
new ClassPathResource("sql/users_activation_dao_queries.properties"),
4948
new ClassPathResource("sql/series_dao_queries.properties"),

src/main/java/ru/mystamps/web/feature/image/ImageConfig.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.springframework.context.annotation.Configuration;
2424
import org.springframework.context.annotation.Import;
2525
import org.springframework.context.annotation.Profile;
26+
import org.springframework.context.annotation.PropertySource;
2627
import org.springframework.core.env.Environment;
2728
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
2829

@@ -49,8 +50,10 @@ public ImageController imageController() {
4950

5051
@RequiredArgsConstructor
5152
@Import({ DbStrategyConfig.class, FsStrategyConfig.class })
53+
@PropertySource("classpath:sql/image_dao_queries.properties")
5254
public static class Services {
5355

56+
private final Environment env;
5457
private final NamedParameterJdbcTemplate jdbcTemplate;
5558
private final ImagePersistenceStrategy imagePersistenceStrategy;
5659

@@ -69,7 +72,7 @@ public ImageService imageService(ImageDao imageDao) {
6972

7073
@Bean
7174
public ImageDao imageDao() {
72-
return new JdbcImageDao(jdbcTemplate);
75+
return new JdbcImageDao(env, jdbcTemplate);
7376
}
7477

7578
}

src/main/java/ru/mystamps/web/feature/image/JdbcImageDao.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
*/
1818
package ru.mystamps.web.feature.image;
1919

20-
import lombok.RequiredArgsConstructor;
2120
import org.apache.commons.lang3.Validate;
22-
import org.springframework.beans.factory.annotation.Value;
21+
import org.springframework.core.env.Environment;
2322
import org.springframework.dao.EmptyResultDataAccessException;
2423
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
2524
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
@@ -32,25 +31,23 @@
3231
import java.util.List;
3332
import java.util.Map;
3433

35-
@RequiredArgsConstructor
3634
public class JdbcImageDao implements ImageDao {
3735

3836
private final NamedParameterJdbcTemplate jdbcTemplate;
37+
private final String addImageSql;
38+
private final String replaceImageSql;
39+
private final String addImageToSeriesSql;
40+
private final String findByIdSql;
41+
private final String findBySeriesIdSql;
3942

40-
@Value("${image.add}")
41-
private String addImageSql;
42-
43-
@Value("${image.replace}")
44-
private String replaceImageSql;
45-
46-
@Value("${series_image.add}")
47-
private String addImageToSeriesSql;
48-
49-
@Value("${image.find_by_id}")
50-
private String findByIdSql;
51-
52-
@Value("${series_image.find_by_series_id}")
53-
private String findBySeriesIdSql;
43+
public JdbcImageDao(Environment env, NamedParameterJdbcTemplate jdbcTemplate) {
44+
this.jdbcTemplate = jdbcTemplate;
45+
this.addImageSql = env.getRequiredProperty("image.add");
46+
this.replaceImageSql = env.getRequiredProperty("image.replace");
47+
this.addImageToSeriesSql = env.getRequiredProperty("series_image.add");
48+
this.findByIdSql = env.getRequiredProperty("image.find_by_id");
49+
this.findBySeriesIdSql = env.getRequiredProperty("series_image.find_by_series_id");
50+
}
5451

5552
@Override
5653
public Integer add(String type, String filename) {

0 commit comments

Comments
 (0)