• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

TAKETODAY / today-infrastructure / 20632861616

01 Jan 2026 04:53AM UTC coverage: 84.18% (-0.3%) from 84.439%
20632861616

push

github

TAKETODAY
:sparkles: ApplicationType 支持通过 SPI 获取

55643 of 70608 branches covered (78.81%)

Branch coverage included in aggregate %.

130472 of 150485 relevant lines covered (86.7%)

3.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.78
today-context/src/main/java/infra/context/support/AbstractRefreshableConfigApplicationContext.java
1
/*
2
 * Copyright 2017 - 2025 the original author or authors.
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 3 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, see [https://www.gnu.org/licenses/]
16
 */
17

18
package infra.context.support;
19

20
import org.jspecify.annotations.Nullable;
21

22
import infra.beans.factory.BeanNameAware;
23
import infra.beans.factory.InitializingBean;
24
import infra.context.ApplicationContext;
25
import infra.core.env.Environment;
26
import infra.lang.Assert;
27
import infra.util.StringUtils;
28

29
/**
30
 * {@link AbstractRefreshableApplicationContext} subclass that adds common handling
31
 * of specified config locations.
32
 *
33
 * @author Juergen Hoeller
34
 * @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
35
 * @see #setConfigLocation
36
 * @see #setConfigLocations
37
 * @see #getDefaultConfigLocations
38
 * @since 4.0 2022/2/20 17:39
39
 */
40
public abstract class AbstractRefreshableConfigApplicationContext extends AbstractRefreshableApplicationContext
41
        implements BeanNameAware, InitializingBean {
42

43
  private String @Nullable [] configLocations;
44

45
  private boolean setIdCalled = false;
6✔
46

47
  /**
48
   * Create a new AbstractRefreshableConfigApplicationContext with no parent.
49
   */
50
  public AbstractRefreshableConfigApplicationContext() { }
3✔
51

52
  /**
53
   * Create a new AbstractRefreshableConfigApplicationContext with the given parent context.
54
   *
55
   * @param parent the parent context
56
   */
57
  public AbstractRefreshableConfigApplicationContext(@Nullable ApplicationContext parent) {
58
    super(parent);
3✔
59
  }
1✔
60

61
  /**
62
   * Set the config locations for this application context in init-param style,
63
   * i.e. with distinct locations separated by commas, semicolons or whitespace.
64
   * <p>If not set, the implementation may use a default as appropriate.
65
   */
66
  public void setConfigLocation(String location) {
67
    setConfigLocations(StringUtils.tokenizeToStringArray(location, CONFIG_LOCATION_DELIMITERS));
5✔
68
  }
1✔
69

70
  /**
71
   * Set the config locations for this application context.
72
   * <p>If not set, the implementation may use a default as appropriate.
73
   */
74
  public void setConfigLocations(String @Nullable ... locations) {
75
    if (locations != null) {
2!
76
      Assert.noNullElements(locations, "Config locations is required");
3✔
77
      this.configLocations = new String[locations.length];
5✔
78
      for (int i = 0; i < locations.length; i++) {
9✔
79
        this.configLocations[i] = resolvePath(locations[i]).trim();
10✔
80
      }
81
    }
82
    else {
83
      this.configLocations = null;
×
84
    }
85
  }
1✔
86

87
  /**
88
   * Return an array of resource locations, referring to the XML bean definition
89
   * files that this context should be built with. Can also include location
90
   * patterns, which will get resolved via a PatternResourceLoader.
91
   * <p>The default implementation returns {@code null}. Subclasses can override
92
   * this to provide a set of resource locations to load bean definitions from.
93
   *
94
   * @return an array of resource locations, or {@code null} if none
95
   * @see #getResources
96
   */
97
  protected String @Nullable [] getConfigLocations() {
98
    return (this.configLocations != null ? this.configLocations : getDefaultConfigLocations());
9✔
99
  }
100

101
  /**
102
   * Return the default config locations to use, for the case where no
103
   * explicit config locations have been specified.
104
   * <p>The default implementation returns {@code null},
105
   * requiring explicit config locations.
106
   *
107
   * @return an array of default config locations, if any
108
   * @see #setConfigLocations
109
   */
110
  protected String @Nullable [] getDefaultConfigLocations() {
111
    return null;
2✔
112
  }
113

114
  /**
115
   * Resolve the given path, replacing placeholders with corresponding
116
   * environment property values if necessary. Applied to config locations.
117
   *
118
   * @param path the original file path
119
   * @return the resolved file path
120
   * @see Environment#resolveRequiredPlaceholders(String)
121
   */
122
  protected String resolvePath(String path) {
123
    return getEnvironment().resolveRequiredPlaceholders(path);
5✔
124
  }
125

126
  @Override
127
  public void setId(String id) {
128
    super.setId(id);
×
129
    this.setIdCalled = true;
×
130
  }
×
131

132
  /**
133
   * Sets the id of this context to the bean name by default,
134
   * for cases where the context instance is itself defined as a bean.
135
   */
136
  @Override
137
  public void setBeanName(String name) {
138
    if (!this.setIdCalled) {
3!
139
      super.setId(name);
3✔
140
      setDisplayName("ApplicationContext '" + name + "'");
4✔
141
    }
142
  }
1✔
143

144
  /**
145
   * Triggers {@link #refresh()} if not refreshed in the concrete context's
146
   * constructor already.
147
   */
148
  @Override
149
  public void afterPropertiesSet() {
150
    if (!isActive()) {
3!
151
      refresh();
×
152
    }
153
  }
1✔
154

155
}
156

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc