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

TAKETODAY / today-infrastructure / 18154768944

01 Oct 2025 07:26AM UTC coverage: 81.882% (-0.005%) from 81.887%
18154768944

push

github

web-flow
Merge pull request #290 from TAKETODAY/dev/jspecify

jspecify

59788 of 78013 branches covered (76.64%)

Branch coverage included in aggregate %.

141239 of 167496 relevant lines covered (84.32%)

3.6 hits per line

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

30.43
today-context/src/main/java/infra/context/support/FileSystemXmlApplicationContext.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.BeansException;
23
import infra.beans.factory.xml.XmlBeanDefinitionReader;
24
import infra.context.ApplicationContext;
25
import infra.core.io.FileSystemResource;
26
import infra.core.io.Resource;
27

28
/**
29
 * Standalone XML application context, taking the context definition files
30
 * from the file system or from URLs, interpreting plain paths as relative
31
 * file system locations (e.g. "mydir/myfile.txt"). Useful for test harnesses
32
 * as well as for standalone environments.
33
 *
34
 * <p><b>NOTE:</b> Plain paths will always be interpreted as relative
35
 * to the current VM working directory, even if they start with a slash.
36
 * (This is consistent with the semantics in a mock container.)
37
 * <b>Use an explicit "file:" prefix to enforce an absolute file path.</b>
38
 *
39
 * <p>The config location defaults can be overridden via {@link #getConfigLocations},
40
 * Config locations can either denote concrete files like "/myfiles/context.xml"
41
 * or Ant-style patterns like "/myfiles/*-context.xml" (see the
42
 * {@link infra.util.AntPathMatcher} javadoc for pattern details).
43
 *
44
 * <p>Note: In case of multiple config locations, later bean definitions will
45
 * override ones defined in earlier loaded files. This can be leveraged to
46
 * deliberately override certain bean definitions via an extra XML file.
47
 *
48
 * <p><b>This is a simple, one-stop shop convenience ApplicationContext.
49
 * Consider using the {@link GenericApplicationContext} class in combination
50
 * with an {@link XmlBeanDefinitionReader}
51
 * for more flexible context setup.</b>
52
 *
53
 * @author Rod Johnson
54
 * @author Juergen Hoeller
55
 * @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
56
 * @see #getResource
57
 * @see #getResourceByPath
58
 * @see GenericApplicationContext
59
 * @since 4.0 2022/3/6 22:14
60
 */
61
public class FileSystemXmlApplicationContext extends AbstractXmlApplicationContext {
62

63
  /**
64
   * Create a new FileSystemXmlApplicationContext for bean-style configuration.
65
   *
66
   * @see #setConfigLocation
67
   * @see #setConfigLocations
68
   * @see #afterPropertiesSet()
69
   */
70
  public FileSystemXmlApplicationContext() { }
×
71

72
  /**
73
   * Create a new FileSystemXmlApplicationContext for bean-style configuration.
74
   *
75
   * @param parent the parent context
76
   * @see #setConfigLocation
77
   * @see #setConfigLocations
78
   * @see #afterPropertiesSet()
79
   */
80
  public FileSystemXmlApplicationContext(ApplicationContext parent) {
81
    super(parent);
×
82
  }
×
83

84
  /**
85
   * Create a new FileSystemXmlApplicationContext, loading the definitions
86
   * from the given XML file and automatically refreshing the context.
87
   *
88
   * @param configLocation file path
89
   * @throws BeansException if context creation failed
90
   */
91
  public FileSystemXmlApplicationContext(String configLocation) throws BeansException {
92
    this(new String[] { configLocation }, true, null);
×
93
  }
×
94

95
  /**
96
   * Create a new FileSystemXmlApplicationContext, loading the definitions
97
   * from the given XML files and automatically refreshing the context.
98
   *
99
   * @param configLocations array of file paths
100
   * @throws BeansException if context creation failed
101
   */
102
  public FileSystemXmlApplicationContext(String... configLocations) throws BeansException {
103
    this(configLocations, true, null);
×
104
  }
×
105

106
  /**
107
   * Create a new FileSystemXmlApplicationContext with the given parent,
108
   * loading the definitions from the given XML files and automatically
109
   * refreshing the context.
110
   *
111
   * @param configLocations array of file paths
112
   * @param parent the parent context
113
   * @throws BeansException if context creation failed
114
   */
115
  public FileSystemXmlApplicationContext(String[] configLocations, ApplicationContext parent) throws BeansException {
116
    this(configLocations, true, parent);
×
117
  }
×
118

119
  /**
120
   * Create a new FileSystemXmlApplicationContext, loading the definitions
121
   * from the given XML files.
122
   *
123
   * @param configLocations array of file paths
124
   * @param refresh whether to automatically refresh the context,
125
   * loading all bean definitions and creating all singletons.
126
   * Alternatively, call refresh manually after further configuring the context.
127
   * @throws BeansException if context creation failed
128
   * @see #refresh()
129
   */
130
  public FileSystemXmlApplicationContext(String[] configLocations, boolean refresh) throws BeansException {
131
    this(configLocations, refresh, null);
5✔
132
  }
1✔
133

134
  /**
135
   * Create a new FileSystemXmlApplicationContext with the given parent,
136
   * loading the definitions from the given XML files.
137
   *
138
   * @param configLocations array of file paths
139
   * @param refresh whether to automatically refresh the context,
140
   * loading all bean definitions and creating all singletons.
141
   * Alternatively, call refresh manually after further configuring the context.
142
   * @param parent the parent context
143
   * @throws BeansException if context creation failed
144
   * @see #refresh()
145
   */
146
  public FileSystemXmlApplicationContext(
147
          String[] configLocations, boolean refresh, @Nullable ApplicationContext parent)
148
          throws BeansException {
149

150
    super(parent);
3✔
151
    setConfigLocations(configLocations);
3✔
152
    if (refresh) {
2!
153
      refresh();
×
154
    }
155
  }
1✔
156

157
  /**
158
   * Resolve resource paths as file system paths.
159
   * <p>Note: Even if a given path starts with a slash, it will get
160
   * interpreted as relative to the current VM working directory.
161
   * This is consistent with the semantics in a mock container.
162
   *
163
   * @param path the path to the resource
164
   * @return the Resource handle
165
   */
166
  @Override
167
  protected Resource getResourceByPath(String path) {
168
    if (path.startsWith("/")) {
×
169
      path = path.substring(1);
×
170
    }
171
    return new FileSystemResource(path);
×
172
  }
173

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

© 2026 Coveralls, Inc