1+ package spring .oldboy .repository ;
2+
3+ import org .springframework .beans .factory .annotation .Value ;
4+ import org .springframework .beans .factory .config .BeanDefinition ;
5+ import org .springframework .context .annotation .Scope ;
6+ import spring .oldboy .entity .Company ;
7+ import spring .oldboy .pool .StarterConnectionPool ;
8+
9+ import javax .annotation .PostConstruct ;
10+ import javax .inject .Inject ;
11+ import javax .inject .Named ;
12+ import java .util .List ;
13+ import java .util .Optional ;
14+
15+ /*
16+ Специально не помечаем данный класс, но его bean будет
17+ создан исходя из настроек resources/application.xml
18+
19+ Поставим scope не singleton - он по умолчанию. И теперь
20+ на каждый новый запрос, мы будем получать новый bean и
21+ не из IoC контейнера.
22+ */
23+ @ Named ("stockRep" )
24+ public class StockRepository {
25+
26+ private final StarterConnectionPool pool1 ;
27+ private final List <StarterConnectionPool > pools ;
28+ private final Integer poolSize ;
29+
30+ @ Inject
31+ public StockRepository (StarterConnectionPool pool1 ,
32+ List <StarterConnectionPool > pools ,
33+ @ Value ("${db.pool.size}" ) Integer poolSize ) {
34+ this .pool1 = pool1 ;
35+ this .pools = pools ;
36+ this .poolSize = poolSize ;
37+ }
38+
39+ public StarterConnectionPool getPool1 () {
40+ return pool1 ;
41+ }
42+
43+ public List <StarterConnectionPool > getPools () {
44+ return pools ;
45+ }
46+
47+ public Integer getPoolSize () {
48+ return poolSize ;
49+ }
50+ }
0 commit comments