Skip to content

Commit e67aca0

Browse files
committed
refactor: move inclusion of site_parser_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 50c092c commit e67aca0

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

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

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public static PropertySourcesPlaceholderConfigurer getPropertySourcesPlaceholder
5252
new ClassPathResource("sql/series_dao_queries.properties"),
5353
new ClassPathResource("sql/series_import_request_dao_queries.properties"),
5454
new ClassPathResource("sql/series_sales_dao_queries.properties"),
55-
new ClassPathResource("sql/site_parser_dao_queries.properties"),
5655
new ClassPathResource("sql/suspicious_activity_dao_queries.properties"),
5756
new ClassPathResource("sql/transaction_participants_dao_queries.properties")
5857
);

src/main/java/ru/mystamps/web/feature/series/importing/event/EventsConfig.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import org.springframework.context.ApplicationListener;
2424
import org.springframework.context.annotation.Bean;
2525
import org.springframework.context.annotation.Configuration;
26+
import org.springframework.context.annotation.PropertySource;
27+
import org.springframework.core.env.Environment;
2628
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
2729
import ru.mystamps.web.config.ServicesConfig;
2830
import ru.mystamps.web.feature.category.CategoryService;
@@ -39,6 +41,7 @@
3941

4042
@Configuration
4143
@RequiredArgsConstructor
44+
@PropertySource("classpath:sql/site_parser_dao_queries.properties")
4245
public class EventsConfig {
4346

4447
private final CategoryService categoryService;
@@ -48,6 +51,7 @@ public class EventsConfig {
4851
private final ServicesConfig servicesConfig;
4952
private final ApplicationEventPublisher eventPublisher;
5053
private final NamedParameterJdbcTemplate jdbcTemplate;
54+
private final Environment env;
5155

5256
@Bean
5357
public SiteParserService siteParserService(SiteParserDao siteParserDao) {
@@ -72,7 +76,7 @@ public SeriesInfoExtractorService seriesInfoExtractorService() {
7276

7377
@Bean
7478
public SiteParserDao siteParserDao() {
75-
return new JdbcSiteParserDao(jdbcTemplate);
79+
return new JdbcSiteParserDao(env, jdbcTemplate);
7680
}
7781

7882
@Bean

src/main/java/ru/mystamps/web/feature/series/importing/extractor/JdbcSiteParserDao.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
*/
1818
package ru.mystamps.web.feature.series.importing.extractor;
1919

20-
import lombok.RequiredArgsConstructor;
21-
import org.springframework.beans.factory.annotation.Value;
20+
import org.springframework.core.env.Environment;
2221
import org.springframework.dao.EmptyResultDataAccessException;
2322
import org.springframework.jdbc.core.ResultSetExtractor;
2423
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
@@ -28,23 +27,24 @@
2827
import java.util.List;
2928
import java.util.Map;
3029

31-
@RequiredArgsConstructor
3230
public class JdbcSiteParserDao implements SiteParserDao {
3331

3432
private static final ResultSetExtractor<Map<String, String>> PARAMS_EXTRACTOR =
3533
new MapStringStringResultSetExtractor("name", "value");
3634

3735
private final NamedParameterJdbcTemplate jdbcTemplate;
38-
39-
@Value("${site_parser.find_like_matched_url}")
40-
private String findParserIdByMatchedUrlSql;
41-
42-
@Value("${site_parser.find_names}")
43-
private String findParserNamesSql;
44-
36+
private final String findParserIdByMatchedUrlSql;
37+
private final String findParserNamesSql;
4538
@SuppressWarnings("PMD.LongVariable")
46-
@Value("${site_parser_param.find_all_with_parser_name}")
47-
private String findParametersWithParserNameSql;
39+
private final String findParametersWithParserNameSql;
40+
41+
@SuppressWarnings("checkstyle:linelength")
42+
public JdbcSiteParserDao(Environment env, NamedParameterJdbcTemplate jdbcTemplate) {
43+
this.jdbcTemplate = jdbcTemplate;
44+
this.findParserIdByMatchedUrlSql = env.getRequiredProperty("site_parser.find_like_matched_url");
45+
this.findParserNamesSql = env.getRequiredProperty("site_parser.find_names");
46+
this.findParametersWithParserNameSql = env.getRequiredProperty("site_parser_param.find_all_with_parser_name");
47+
}
4848

4949
@Override
5050
public Integer findParserIdForUrl(String url) {

0 commit comments

Comments
 (0)