Skip to content

Commit 87bd97b

Browse files
committed
Explicitly define services and controllers in application context.
No functional changes.
1 parent 42ebaaa commit 87bd97b

File tree

8 files changed

+127
-13
lines changed

8 files changed

+127
-13
lines changed

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

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

20-
import org.springframework.context.annotation.ComponentScan;
2120
import org.springframework.context.annotation.Configuration;
2221
import org.springframework.context.annotation.Import;
2322

2423
@Configuration
2524
@Import({
2625
DbConfig.class,
27-
SecurityConfig.class
28-
})
29-
@ComponentScan(basePackages = {
30-
"ru.mystamps.web.service"
26+
SecurityConfig.class,
27+
ServicesConfig.class
3128
})
3229
public class ApplicationContext {
3330
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (C) 2009-2013 Slava Semushin <slava.semushin@gmail.com>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*/
18+
package ru.mystamps.web.config;
19+
20+
import javax.inject.Inject;
21+
22+
import org.springframework.context.annotation.Bean;
23+
import org.springframework.context.annotation.Configuration;
24+
25+
import ru.mystamps.web.controller.*; // NOCHECKSTYLE: AvoidStarImportCheck
26+
27+
@Configuration
28+
public class ControllersConfig {
29+
30+
@Inject
31+
private ServicesConfig servicesConfig;
32+
33+
@Bean
34+
public AccountController getAccountController() {
35+
return new AccountController(servicesConfig.getUserService());
36+
}
37+
38+
@Bean
39+
public CountryController getCountryController() {
40+
return new CountryController(servicesConfig.getCountryService());
41+
}
42+
43+
@Bean
44+
public ImageController getImageController() {
45+
return new ImageController();
46+
}
47+
48+
@Bean
49+
public NotFoundErrorController getNotFoundErrorController() {
50+
return new NotFoundErrorController(servicesConfig.getSiteService());
51+
}
52+
53+
@Bean
54+
public SeriesController getSeriesController() {
55+
return new SeriesController(
56+
servicesConfig.getCountryService(),
57+
servicesConfig.getSeriesService()
58+
);
59+
}
60+
61+
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import java.util.List;
2323

2424
import org.springframework.context.annotation.Bean;
25-
import org.springframework.context.annotation.ComponentScan;
2625
import org.springframework.context.annotation.Configuration;
26+
import org.springframework.context.annotation.Import;
2727
import org.springframework.context.MessageSource;
2828
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
2929
import org.springframework.data.repository.support.DomainClassConverter;
@@ -51,9 +51,7 @@
5151
@Configuration
5252
@EnableWebMvc
5353
@EnableScheduling
54-
@ComponentScan(basePackages = {
55-
"ru.mystamps.web.controller"
56-
})
54+
@Import(ControllersConfig.class)
5755
public class MvcConfig extends WebMvcConfigurerAdapter {
5856

5957
@Override
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (C) 2009-2013 Slava Semushin <slava.semushin@gmail.com>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*/
18+
package ru.mystamps.web.config;
19+
20+
import org.springframework.context.annotation.Bean;
21+
import org.springframework.context.annotation.Configuration;
22+
23+
import ru.mystamps.web.service.*; // NOCHECKSTYLE: AvoidStarImportCheck
24+
25+
@Configuration
26+
public class ServicesConfig {
27+
28+
@Bean
29+
public CountryService getCountryService() {
30+
return new CountryServiceImpl();
31+
}
32+
33+
@Bean
34+
public CronService getCronService() {
35+
return new CronServiceImpl();
36+
}
37+
38+
@Bean
39+
public ImageService getImageService() {
40+
return new ImageServiceImpl();
41+
}
42+
43+
@Bean
44+
public SeriesService getSeriesService() {
45+
return new SeriesServiceImpl();
46+
}
47+
48+
@Bean
49+
public SiteService getSiteService() {
50+
return new SiteServiceImpl();
51+
}
52+
53+
@Bean
54+
public UserService getUserService() {
55+
return new UserServiceImpl();
56+
}
57+
58+
}

src/main/java/ru/mystamps/web/controller/AccountController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class AccountController {
4949
private final UserService userService;
5050

5151
@Inject
52-
AccountController(UserService userService) {
52+
public AccountController(UserService userService) {
5353
this.userService = userService;
5454
}
5555

src/main/java/ru/mystamps/web/controller/CountryController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class CountryController {
4242
private final CountryService countryService;
4343

4444
@Inject
45-
CountryController(CountryService countryService) {
45+
public CountryController(CountryService countryService) {
4646
this.countryService = countryService;
4747
}
4848

src/main/java/ru/mystamps/web/controller/NotFoundErrorController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class NotFoundErrorController {
4141
private final SiteService siteService;
4242

4343
@Inject
44-
NotFoundErrorController(SiteService siteService) {
44+
public NotFoundErrorController(SiteService siteService) {
4545
this.siteService = siteService;
4646
}
4747

src/main/java/ru/mystamps/web/controller/SeriesController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class SeriesController {
6666
}
6767

6868
@Inject
69-
SeriesController(CountryService countryService, SeriesService seriesService) {
69+
public SeriesController(CountryService countryService, SeriesService seriesService) {
7070
this.countryService = countryService;
7171
this.seriesService = seriesService;
7272
}

0 commit comments

Comments
 (0)