proj_name stringclasses 131
values | relative_path stringlengths 30 228 | class_name stringlengths 1 68 | func_name stringlengths 1 48 | masked_class stringlengths 78 9.82k | func_body stringlengths 46 9.61k | len_input int64 29 2.01k | len_output int64 14 1.94k | total int64 55 2.05k | relevant_context stringlengths 0 38.4k |
|---|---|---|---|---|---|---|---|---|---|
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaHealthCheckHandler.java | EurekaHealthCheckHandler | getOrder | class EurekaHealthCheckHandler
implements HealthCheckHandler, ApplicationContextAware, InitializingBean, Ordered, Lifecycle {
private static final Map<Status, InstanceInfo.InstanceStatus> STATUS_MAPPING = new HashMap<>() {
{
put(Status.UNKNOWN, InstanceStatus.UNKNOWN);
put(Status.OUT_OF_SERVICE, InstanceSta... |
// registered with a high order priority so the close() method is invoked early
// and *BEFORE* EurekaAutoServiceRegistration
// (must be in effect when the registration is closed and the eureka replication
// triggered -> health check handler is
// consulted at that moment)
return Ordered.HIGHEST_PRECEDEN... | 1,317 | 91 | 1,408 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaHealthIndicator.java | EurekaHealthIndicator | health | class EurekaHealthIndicator implements DiscoveryHealthIndicator {
private final EurekaClient eurekaClient;
private final EurekaInstanceConfig instanceConfig;
private final EurekaClientConfig clientConfig;
public EurekaHealthIndicator(EurekaClient eurekaClient, EurekaInstanceConfig instanceConfig,
EurekaClien... |
Builder builder = Health.unknown();
Status status = getStatus(builder);
return builder.status(status).withDetail("applications", getApplications()).build();
| 689 | 44 | 733 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaServiceInstance.java | EurekaServiceInstance | equals | class EurekaServiceInstance implements ServiceInstance {
private final InstanceInfo instance;
public EurekaServiceInstance(InstanceInfo instance) {
Assert.notNull(instance, "Service instance required");
this.instance = instance;
}
public InstanceInfo getInstanceInfo() {
return instance;
}
@Override
pub... |
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
EurekaServiceInstance that = (EurekaServiceInstance) o;
return Objects.equals(this.instance, that.instance);
| 401 | 82 | 483 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/InstanceInfoFactory.java | InstanceInfoFactory | create | class InstanceInfoFactory {
private static final Log log = LogFactory.getLog(InstanceInfoFactory.class);
public InstanceInfo create(EurekaInstanceConfig config) {<FILL_FUNCTION_BODY>}
} |
LeaseInfo.Builder leaseInfoBuilder = LeaseInfo.Builder.newBuilder()
.setRenewalIntervalInSecs(config.getLeaseRenewalIntervalInSeconds())
.setDurationInSecs(config.getLeaseExpirationDurationInSeconds());
// Builder the instance information to be registered with eureka
// server
InstanceInfo.Builder bui... | 58 | 744 | 802 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/RestTemplateTimeoutProperties.java | RestTemplateTimeoutProperties | equals | class RestTemplateTimeoutProperties {
/**
* Default values are set to 180000, in keeping with {@link RequestConfig} and
* {@link SocketConfig} defaults.
*/
private int connectTimeout = 3 * 60 * 1000;
private int connectRequestTimeout = 3 * 60 * 1000;
private int socketTimeout = 3 * 60 * 1000;
public int ... |
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
RestTemplateTimeoutProperties that = (RestTemplateTimeoutProperties) o;
return connectTimeout == that.connectTimeout && connectRequestTimeout == that.connectRequestTimeout
&& socketTimeout == that.soc... | 354 | 97 | 451 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/DiscoveryClientOptionalArgsConfiguration.java | DiscoveryClientOptionalArgsConfiguration | setupTLS | class DiscoveryClientOptionalArgsConfiguration {
protected static final Log logger = LogFactory.getLog(DiscoveryClientOptionalArgsConfiguration.class);
@Bean
@ConfigurationProperties("eureka.client.tls")
public TlsProperties tlsProperties() {
return new TlsProperties();
}
@Bean
@ConditionalOnClass(name = "o... |
if (properties.isEnabled()) {
SSLContextFactory factory = new SSLContextFactory(properties);
args.setSSLContext(factory.createSSLContext());
}
| 1,292 | 46 | 1,338 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaClientConfigServerAutoConfiguration.java | EurekaClientConfigServerAutoConfiguration | init | class EurekaClientConfigServerAutoConfiguration {
@Autowired(required = false)
private EurekaInstanceConfig instance;
@Autowired
private Environment env;
@PostConstruct
public void init() {<FILL_FUNCTION_BODY>}
} |
if (this.instance == null) {
return;
}
String prefix = this.env.getProperty("spring.cloud.config.server.prefix");
if (StringUtils.hasText(prefix) && !StringUtils.hasText(this.instance.getMetadataMap().get("configPath"))) {
this.instance.getMetadataMap().put("configPath", prefix);
}
| 68 | 98 | 166 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapper.java | EurekaConfigServerBootstrapper | initialize | class EurekaConfigServerBootstrapper implements BootstrapRegistryInitializer {
@Override
public void initialize(BootstrapRegistry registry) {<FILL_FUNCTION_BODY>}
private static PropertyResolver getPropertyResolver(BootstrapContext context) {
return context.getOrElseSupply(PropertyResolver.class,
() -> new P... |
if (!ClassUtils.isPresent("org.springframework.cloud.config.client.ConfigServerInstanceProvider", null)) {
return;
}
registry.registerIfAbsent(EurekaClientConfigBean.class, context -> {
if (!getDiscoveryEnabled(context)) {
return null;
}
PropertyResolver propertyResolver = getPropertyResolver(co... | 223 | 342 | 565 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerInstanceProvider.java | EurekaConfigServerInstanceProvider | getInstances | class EurekaConfigServerInstanceProvider {
private final Log log;
private final EurekaHttpClient client;
private final EurekaClientConfig config;
public EurekaConfigServerInstanceProvider(EurekaHttpClient client, EurekaClientConfig config) {
this(LogFactory.getLog(EurekaConfigServerInstanceProvider.class), cl... |
if (log.isDebugEnabled()) {
log.debug("eurekaConfigServerInstanceProvider finding instances for " + serviceId);
}
String remoteRegionsStr = config.fetchRegistryForRemoteRegions();
String[] remoteRegions = remoteRegionsStr == null ? null : remoteRegionsStr.split(",");
EurekaHttpResponse<Applications> respo... | 237 | 338 | 575 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/HostnameBasedUrlRandomizer.java | HostnameBasedUrlRandomizer | randomEndpoint | class HostnameBasedUrlRandomizer implements EndpointUtils.ServiceUrlRandomizer {
private static final String EUREKA_INSTANCE_HOSTNAME = "eureka.instance.hostname";
private final String hostname;
HostnameBasedUrlRandomizer(String hostname) {
this.hostname = hostname;
}
@Override
public void randomize(List<St... |
String hostname = binder.bind(EUREKA_INSTANCE_HOSTNAME, String.class).orElseGet(() -> null);
return new DefaultEndpoint(getEurekaUrl(config, hostname));
| 547 | 57 | 604 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/DefaultEurekaClientHttpRequestFactorySupplier.java | DefaultEurekaClientHttpRequestFactorySupplier | get | class DefaultEurekaClientHttpRequestFactorySupplier implements EurekaClientHttpRequestFactorySupplier {
private final RestTemplateTimeoutProperties restTemplateTimeoutProperties;
/**
* @deprecated in favour of
* {@link DefaultEurekaClientHttpRequestFactorySupplier#DefaultEurekaClientHttpRequestFactorySupplier(R... |
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
if (sslContext != null || hostnameVerifier != null || restTemplateTimeoutProperties != null) {
httpClientBuilder.setConnectionManager(
buildConnectionManager(sslContext, hostnameVerifier, restTemplateTimeoutProperties));
}
if (restTempla... | 546 | 170 | 716 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateEurekaHttpClient.java | RestTemplateEurekaHttpClient | register | class RestTemplateEurekaHttpClient implements EurekaHttpClient {
private final RestTemplate restTemplate;
private String serviceUrl;
public RestTemplateEurekaHttpClient(RestTemplate restTemplate, String serviceUrl) {
this.restTemplate = restTemplate;
this.serviceUrl = serviceUrl;
if (!serviceUrl.endsWith("/... |
String urlPath = serviceUrl + "apps/" + info.getAppName();
HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.ACCEPT_ENCODING, "gzip");
headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
ResponseEntity<Void> response = restTemplate.exchange(urlPath, HttpMethod.POST, new ... | 1,755 | 153 | 1,908 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/WebClientEurekaHttpClient.java | WebClientEurekaHttpClient | statusUpdate | class WebClientEurekaHttpClient implements EurekaHttpClient {
private WebClient webClient;
public WebClientEurekaHttpClient(WebClient webClient) {
this.webClient = webClient;
}
@Override
public EurekaHttpResponse<Void> register(InstanceInfo info) {
return webClient.post().uri("apps/" + info.getAppName()).bo... |
String urlPath = "apps/" + appName + '/' + id + "/status?value=" + newStatus.name() + "&lastDirtyTimestamp="
+ info.getLastDirtyTimestamp().toString();
return webClient.put().uri(urlPath).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.retrieve().onStatus(HttpStatusCode::isError, this:... | 1,874 | 133 | 2,007 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/WebClientTransportClientFactory.java | WebClientTransportClientFactory | http4XxErrorExchangeFilterFunction | class WebClientTransportClientFactory implements TransportClientFactory {
private final Supplier<WebClient.Builder> builderSupplier;
public WebClientTransportClientFactory(Supplier<WebClient.Builder> builderSupplier) {
this.builderSupplier = builderSupplier;
}
@Override
public EurekaHttpClient newClient(Eurek... |
return ExchangeFilterFunction.ofResponseProcessor(clientResponse -> {
// literally 400 pass the tests, not 4xxClientError
if (clientResponse.statusCode().value() == 400) {
ClientResponse newResponse = clientResponse.mutate().statusCode(HttpStatus.OK).build();
newResponse.body((clientHttpResponse, conte... | 985 | 222 | 1,207 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/loadbalancer/EurekaLoadBalancerClientConfiguration.java | EurekaLoadBalancerClientConfiguration | getZoneFromEureka | class EurekaLoadBalancerClientConfiguration {
private static final Log LOG = LogFactory.getLog(EurekaLoadBalancerClientConfiguration.class);
private final EurekaClientConfig clientConfig;
private final EurekaInstanceConfig eurekaConfig;
private final LoadBalancerZoneConfig zoneConfig;
private final EurekaLoad... |
String zone;
boolean approximateZoneFromHostname = eurekaLoadBalancerProperties.isApproximateZoneFromHostname();
if (approximateZoneFromHostname && eurekaConfig != null) {
return ZoneUtils.extractApproximateZone(this.eurekaConfig.getHostName(false));
}
else {
zone = eurekaConfig == null ? null : eureka... | 375 | 207 | 582 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/metadata/DefaultManagementMetadataProvider.java | DefaultManagementMetadataProvider | constructValidUrl | class DefaultManagementMetadataProvider implements ManagementMetadataProvider {
private static final int RANDOM_PORT = 0;
private static final Log log = LogFactory.getLog(DefaultManagementMetadataProvider.class);
@Override
public ManagementMetadata get(EurekaInstanceConfigBean instance, int serverPort, String se... |
try {
if (!contextPath.endsWith("/")) {
contextPath = contextPath + "/";
}
String refinedContextPath = '/' + StringUtils.trimLeadingCharacter(contextPath, '/');
URL base = new URL(scheme, hostname, port, refinedContextPath);
String refinedStatusPath = refinedStatusPath(statusPath, contextPath);
... | 1,044 | 161 | 1,205 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/metadata/ManagementMetadata.java | ManagementMetadata | equals | class ManagementMetadata {
private final String healthCheckUrl;
private final String statusPageUrl;
private final Integer managementPort;
private String secureHealthCheckUrl;
public ManagementMetadata(String healthCheckUrl, String statusPageUrl, Integer managementPort) {
this.healthCheckUrl = healthCheckUrl... |
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ManagementMetadata that = (ManagementMetadata) o;
return Objects.equals(healthCheckUrl, that.healthCheckUrl) && Objects.equals(statusPageUrl, that.statusPageUrl)
&& Objects.equals(managementPort, that.m... | 388 | 110 | 498 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/reactive/EurekaReactiveDiscoveryClient.java | EurekaReactiveDiscoveryClient | getServices | class EurekaReactiveDiscoveryClient implements ReactiveDiscoveryClient {
private final EurekaClient eurekaClient;
private final EurekaClientConfig clientConfig;
public EurekaReactiveDiscoveryClient(EurekaClient eurekaClient, EurekaClientConfig clientConfig) {
this.eurekaClient = eurekaClient;
this.clientConfi... |
return Flux.defer(() -> Mono.justOrEmpty(eurekaClient.getApplications()))
.flatMapIterable(Applications::getRegisteredApplications)
.filter(application -> !application.getInstances().isEmpty()).map(Application::getName)
.map(String::toLowerCase);
| 274 | 81 | 355 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaAutoServiceRegistration.java | EurekaAutoServiceRegistration | start | class EurekaAutoServiceRegistration
implements AutoServiceRegistration, SmartLifecycle, Ordered, SmartApplicationListener {
private static final Log log = LogFactory.getLog(EurekaAutoServiceRegistration.class);
private final AtomicBoolean running = new AtomicBoolean(false);
private final int order = 0;
privat... |
// only set the port if the nonSecurePort or securePort is 0 and port != 0
if (port.get() != 0) {
if (registration.getNonSecurePort() == 0) {
registration.setNonSecurePort(port.get());
}
if (registration.getSecurePort() == 0 && registration.isSecure()) {
registration.setSecurePort(port.get());
... | 667 | 244 | 911 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaRegistration.java | Builder | build | class Builder {
private final CloudEurekaInstanceConfig instanceConfig;
private ApplicationInfoManager applicationInfoManager;
private EurekaClient eurekaClient;
private ObjectProvider<HealthCheckHandler> healthCheckHandler;
private EurekaClientConfig clientConfig;
private ApplicationEventPublisher pu... |
Assert.notNull(instanceConfig, "instanceConfig may not be null");
if (this.applicationInfoManager == null) {
InstanceInfo instanceInfo = new InstanceInfoFactory().create(this.instanceConfig);
this.applicationInfoManager = new ApplicationInfoManager(this.instanceConfig, instanceInfo);
}
if (this.eu... | 355 | 264 | 619 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaServiceRegistry.java | EurekaServiceRegistry | deregister | class EurekaServiceRegistry implements ServiceRegistry<EurekaRegistration> {
private static final Log log = LogFactory.getLog(EurekaServiceRegistry.class);
private EurekaInstanceConfigBean eurekaInstanceConfigBean;
public EurekaServiceRegistry() {
}
public EurekaServiceRegistry(EurekaInstanceConfigBean eureka... |
if (reg.getApplicationInfoManager().getInfo() != null) {
if (log.isInfoEnabled()) {
log.info("Unregistering application " + reg.getApplicationInfoManager().getInfo().getAppName()
+ " with eureka with status DOWN");
}
reg.getApplicationInfoManager().setInstanceStatus(InstanceInfo.InstanceStatus.D... | 851 | 151 | 1,002 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/support/ZoneUtils.java | ZoneUtils | extractApproximateZone | class ZoneUtils {
private ZoneUtils() {
throw new AssertionError("Must not instantiate utility class.");
}
/**
* Approximates Eureka zones from a host name. This method approximates the zone to be
* everything after the first "." in the host name.
* @param host The host name to extract the host name from
... |
String[] split = StringUtils.split(host, ".");
return split == null ? host : split[1];
| 126 | 31 | 157 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/CloudJacksonJson.java | CloudJacksonJson | updateIfNeeded | class CloudJacksonJson extends LegacyJacksonJson {
protected final CloudJacksonCodec codec = new CloudJacksonCodec();
public CloudJacksonCodec getCodec() {
return codec;
}
@Override
public String codecName() {
return getCodecName(LegacyJacksonJson.class);
}
@Override
public <T> String encode(T object) {... |
if (info.getInstanceId() == null && info.getMetadata() != null) {
String instanceId = info.getMetadata().get("instanceId");
if (StringUtils.hasText(instanceId)) {
// backwards compatibility for Angel
if (StringUtils.hasText(info.getHostName()) && !instanceId.startsWith(info.getHostName())) {
insta... | 1,238 | 148 | 1,386 | <methods>public void <init>() ,public java.lang.String codecName() ,public T decode(java.lang.String, Class<T>) throws java.io.IOException,public T decode(java.io.InputStream, Class<T>) throws java.io.IOException,public java.lang.String encode(T) throws java.io.IOException,public void encode(T, java.io.OutputStream) th... |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaDashboardProperties.java | EurekaDashboardProperties | toString | class EurekaDashboardProperties {
/**
* The path to the Eureka dashboard (relative to the servlet path). Defaults to "/".
*/
private String path = "/";
/**
* Flag to enable the Eureka dashboard. Default true.
*/
private boolean enabled = true;
public String getPath() {
return path;
}
public void se... |
final StringBuilder sb = new StringBuilder("EurekaDashboardProperties{");
sb.append("path='").append(path).append('\'');
sb.append(", enabled=").append(enabled);
sb.append('}');
return sb.toString();
| 303 | 74 | 377 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaProperties.java | EurekaProperties | equals | class EurekaProperties {
/**
* Eureka environment. Defaults to "test".
*/
private String environment = "test";
/**
* Eureka datacenter. Defaults to "default".
*/
private String datacenter = "default";
public String getEnvironment() {
return environment;
}
public void setEnvironment(String environme... |
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
EurekaProperties that = (EurekaProperties) o;
return Objects.equals(datacenter, that.datacenter) && Objects.equals(environment, that.environment);
| 291 | 94 | 385 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerBootstrap.java | EurekaServerBootstrap | initEurekaServerContext | class EurekaServerBootstrap {
private static final Log log = LogFactory.getLog(EurekaServerBootstrap.class);
protected EurekaServerConfig eurekaServerConfig;
protected ApplicationInfoManager applicationInfoManager;
protected EurekaClientConfig eurekaClientConfig;
protected PeerAwareInstanceRegistry registry;
... |
// For backward compatibility
JsonXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(), XStream.PRIORITY_VERY_HIGH);
XmlXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(), XStream.PRIORITY_VERY_HIGH);
if (isAws(this.applicationInfoManager.getInfo())) {
this.aws... | 760 | 256 | 1,016 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerInitializerConfiguration.java | EurekaServerInitializerConfiguration | start | class EurekaServerInitializerConfiguration implements ServletContextAware, SmartLifecycle, Ordered {
private static final Log log = LogFactory.getLog(EurekaServerInitializerConfiguration.class);
@Autowired
private EurekaServerConfig eurekaServerConfig;
private ServletContext servletContext;
@Autowired
private... |
new Thread(() -> {
try {
// TODO: is this class even needed now?
eurekaServerBootstrap.contextInitialized(EurekaServerInitializerConfiguration.this.servletContext);
log.info("Started Eureka Server");
publish(new EurekaRegistryAvailableEvent(getEurekaServerConfig()));
EurekaServerInitializerCo... | 360 | 177 | 537 | <no_super_class> |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/InstanceRegistry.java | InstanceRegistry | handleRenewal | class InstanceRegistry extends PeerAwareInstanceRegistryImpl implements ApplicationContextAware {
private static final Log log = LogFactory.getLog(InstanceRegistry.class);
private ApplicationContext ctxt;
private final int defaultOpenForTrafficCount;
public InstanceRegistry(EurekaServerConfig serverConfig, Eure... |
log("renewed " + appName + ", serverId " + serverId + ", isReplication " + isReplication);
final Application application = getApplication(appName);
if (application != null) {
final InstanceInfo instanceInfo = application.getByInstanceId(serverId);
if (instanceInfo != null) {
publishEvent(new EurekaInst... | 1,172 | 127 | 1,299 | <methods>public void <init>(com.netflix.eureka.EurekaServerConfig, com.netflix.discovery.EurekaClientConfig, com.netflix.eureka.resources.ServerCodecs, com.netflix.discovery.EurekaClient, com.netflix.eureka.transport.EurekaServerHttpClientFactory) ,public boolean cancel(java.lang.String, java.lang.String, boolean) ,pub... |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/event/EurekaInstanceCanceledEvent.java | EurekaInstanceCanceledEvent | equals | class EurekaInstanceCanceledEvent extends ApplicationEvent {
private String appName;
private String serverId;
private boolean replication;
public EurekaInstanceCanceledEvent(Object source, String appName, String serverId, boolean replication) {
super(source);
this.appName = appName;
this.serverId = server... |
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
EurekaInstanceCanceledEvent that = (EurekaInstanceCanceledEvent) o;
return this.replication == that.replication && Objects.equals(this.appName, that.appName)
&& Objects.equals(this.serverId, that.server... | 362 | 116 | 478 | <methods>public void <init>(java.lang.Object) ,public void <init>(java.lang.Object, java.time.Clock) ,public final long getTimestamp() <variables>private static final long serialVersionUID,private final long timestamp |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/event/EurekaInstanceRegisteredEvent.java | EurekaInstanceRegisteredEvent | equals | class EurekaInstanceRegisteredEvent extends ApplicationEvent {
private InstanceInfo instanceInfo;
private int leaseDuration;
private boolean replication;
public EurekaInstanceRegisteredEvent(Object source, InstanceInfo instanceInfo, int leaseDuration,
boolean replication) {
super(source);
this.instanceIn... |
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
EurekaInstanceRegisteredEvent that = (EurekaInstanceRegisteredEvent) o;
return this.leaseDuration == that.leaseDuration && this.replication == that.replication
&& Objects.equals(this.instanceInfo, that.... | 373 | 110 | 483 | <methods>public void <init>(java.lang.Object) ,public void <init>(java.lang.Object, java.time.Clock) ,public final long getTimestamp() <variables>private static final long serialVersionUID,private final long timestamp |
spring-cloud_spring-cloud-netflix | spring-cloud-netflix/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/event/EurekaInstanceRenewedEvent.java | EurekaInstanceRenewedEvent | equals | class EurekaInstanceRenewedEvent extends ApplicationEvent {
private String appName;
private String serverId;
private InstanceInfo instanceInfo;
private boolean replication;
public EurekaInstanceRenewedEvent(Object source, String appName, String serverId, InstanceInfo instanceInfo,
boolean replication) {
... |
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
EurekaInstanceRenewedEvent that = (EurekaInstanceRenewedEvent) o;
return Objects.equals(appName, that.appName) && Objects.equals(serverId, that.serverId)
&& Objects.equals(instanceInfo, that.instanceInf... | 460 | 128 | 588 | <methods>public void <init>(java.lang.Object) ,public void <init>(java.lang.Object, java.time.Clock) ,public final long getTimestamp() <variables>private static final long serialVersionUID,private final long timestamp |
xuchengsheng_spring-reading | spring-reading/spring-annotation/spring-annotation-autowired/src/main/java/com/xcs/spring/AutowiredApplication.java | AutowiredApplication | main | class AutowiredApplication {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfiguration.class);
MyController controller = context.getBean(MyController.class);
controller.showService();
| 34 | 47 | 81 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-annotation/spring-annotation-componentScan/src/main/java/com/xcs/spring/ComponentScanApplication.java | ComponentScanApplication | main | class ComponentScanApplication {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfiguration.class);
for (String beanDefinitionName : context.getBeanDefinitionNames()) {
System.out.println("beanName = " + beanDefinitionName);
}
| 33 | 61 | 94 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-annotation/spring-annotation-conditional/src/main/java/com/xcs/spring/bean/ConditionBeanApplication.java | ConditionBeanApplication | main | class ConditionBeanApplication {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
System.setProperty("enable.bean","false");
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyBeanConfiguration.class);
for (String beanDefinitionName : context.getBeanDefinitionNames()) {
System.out.println("beanDefinitionName = " + beanDefinition... | 33 | 76 | 109 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-annotation/spring-annotation-conditional/src/main/java/com/xcs/spring/configuration/ConditionConfigurationApplication.java | ConditionConfigurationApplication | main | class ConditionConfigurationApplication {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
System.setProperty("enable.config","false");
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfigConfiguration.class);
for (String beanDefinitionName : context.getBeanDefinitionNames()) {
System.out.println("beanDefinitionName = " + beanDefini... | 33 | 76 | 109 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-annotation/spring-annotation-conditional/src/main/java/com/xcs/spring/custom/ConditionCustomApplication.java | ConditionCustomApplication | main | class ConditionCustomApplication {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
System.setProperty("enable.custom","false");
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyCustomConfiguration.class);
for (String beanDefinitionName : context.getBeanDefinitionNames()) {
System.out.println("beanDefinitionName = " + beanDefini... | 33 | 76 | 109 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-annotation/spring-annotation-configuration/src/main/java/com/xcs/spring/ConfigurationApplication.java | ConfigurationApplication | main | class ConfigurationApplication {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfiguration.class);
MyConfiguration configuration = context.getBean(MyConfiguration.class);
System.out.println(configuration.myBean());
System.out.println(configuration.myBean());
| 32 | 67 | 99 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-annotation/spring-annotation-import/src/main/java/com/xcs/spring/ImportApplication.java | ImportApplication | main | class ImportApplication {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfiguration.class);
for (String beanDefinitionName : context.getBeanDefinitionNames()) {
System.out.println("beanName = " + beanDefinitionName);
}
| 32 | 61 | 93 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-annotation/spring-annotation-lazy/src/main/java/com/xcs/spring/LazyApplication.java | LazyApplication | main | class LazyApplication {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
System.out.println("启动 Spring ApplicationContext...");
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfiguration.class);
System.out.println("启动完成 Spring ApplicationContext...");
System.out.println("获取MyService...");
MyService myService ... | 33 | 106 | 139 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-annotation/spring-annotation-propertySource/src/main/java/com/xcs/spring/PropertySourceApplication.java | PropertySourceApplication | main | class PropertySourceApplication {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfiguration.class);
System.out.println("apiVersion = " + context.getEnvironment().getProperty("apiVersion"));
System.out.println("kind = " + context.getEnvironment().getProperty("kind"));
| 33 | 70 | 103 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-annotation/spring-annotation-value/src/main/java/com/xcs/spring/service/MyService.java | MyService | afterPropertiesSet | class MyService implements InitializingBean {
/**
* 直接注入值
*/
@Value("Some String Value")
private String someString;
/**
* 从属性文件中注入值方式
*/
@Value("${app.name}")
private String appName;
/**
* 使用默认值方式
*/
@Value("${app.description:我是默认值}")
private String a... |
System.out.println("直接注入值: " + someString);
System.out.println("从属性文件中注入值: " + appName);
System.out.println("使用默认值: " + appDescription);
System.out.println("注入列表和属性: " + servers);
System.out.println("使用Spring的SpEL: " + sumOfValues);
System.out.println("firstName: " + fir... | 264 | 118 | 382 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-advice-afterReturningAdvice/src/main/java/com/xcs/spring/AfterReturningAdviceDemo.java | AfterReturningAdviceDemo | main | class AfterReturningAdviceDemo {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// 创建代理工厂&创建目标对象
ProxyFactory proxyFactory = new ProxyFactory(new MyService());
// 创建通知
proxyFactory.addAdvice(new MyAfterReturningAdvice());
// 获取代理对象
MyService proxy = (MyService) proxyFactory.getProxy();
// 调用代理对象的方法
proxy.doSomething();
| 37 | 93 | 130 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-advice-afterReturningAdvice/src/main/java/com/xcs/spring/MyAfterReturningAdvice.java | MyAfterReturningAdvice | afterReturning | class MyAfterReturningAdvice implements AfterReturningAdvice {
@Override
public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {<FILL_FUNCTION_BODY>}
} |
System.out.println("After method " + method.getName() + " is called, returned value: " + returnValue);
| 60 | 32 | 92 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-advice-introductionInterceptor/src/main/java/com/xcs/spring/IntroductionInterceptorDemo.java | IntroductionInterceptorDemo | main | class IntroductionInterceptorDemo {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// 创建代理工厂&创建目标对象
ProxyFactory proxyFactory = new ProxyFactory(new MyService());
// 强制私用CGLIB
proxyFactory.setProxyTargetClass(true);
// 创建通知
proxyFactory.addAdvisor(new DefaultIntroductionAdvisor(new MyMonitoringIntroductionAdvice(), MyMonitoringCapable.class));
... | 36 | 170 | 206 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-advice-introductionInterceptor/src/main/java/com/xcs/spring/MyMonitoringIntroductionAdvice.java | MyMonitoringIntroductionAdvice | doProceed | class MyMonitoringIntroductionAdvice extends DelegatingIntroductionInterceptor implements MyMonitoringCapable {
private boolean active = false;
public void setActive(boolean active) {
this.active = active;
}
@Override
public void toggleMonitoring() {
setActive(true);
}
//... |
if (this.active) {
System.out.println("开启监控...");
long startTime = System.currentTimeMillis();
Object result = super.doProceed(mi);
long endTime = System.currentTimeMillis();
System.out.println(mi.getClass().getName() + "." + mi.getMethod().getName() ... | 140 | 143 | 283 | <methods>public void <init>(java.lang.Object) ,public java.lang.Object invoke(org.aopalliance.intercept.MethodInvocation) throws java.lang.Throwable<variables>private java.lang.Object delegate |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-advice-methodBeforeAdvice/src/main/java/com/xcs/spring/MethodBeforeAdviceDemo.java | MethodBeforeAdviceDemo | main | class MethodBeforeAdviceDemo {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// 创建代理工厂&创建目标对象
ProxyFactory proxyFactory = new ProxyFactory(new MyService());
// 创建通知
proxyFactory.addAdvice(new MyMethodBeforeAdvice());
// 获取代理对象
MyService proxy = (MyService) proxyFactory.getProxy();
// 调用代理对象的方法
proxy.doSomething();
| 36 | 92 | 128 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-advice-methodBeforeAdvice/src/main/java/com/xcs/spring/MyMethodBeforeAdvice.java | MyMethodBeforeAdvice | before | class MyMethodBeforeAdvice implements MethodBeforeAdvice {
@Override
public void before(Method method, Object[] args, Object target) throws Throwable {<FILL_FUNCTION_BODY>}
} |
System.out.println("Before method " + method.getName() + " is called.");
| 52 | 24 | 76 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-advice-methodInterceptor/src/main/java/com/xcs/spring/MethodInterceptorDemo.java | MethodInterceptorDemo | main | class MethodInterceptorDemo {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// 创建代理工厂&创建目标对象
ProxyFactory proxyFactory = new ProxyFactory(new MyService());
// 创建通知
proxyFactory.addAdvice(new MyMethodInterceptor());
// 获取代理对象
MyService proxy = (MyService) proxyFactory.getProxy();
// 调用代理对象的方法
proxy.doSomething();
| 36 | 92 | 128 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-advice-methodInterceptor/src/main/java/com/xcs/spring/MyMethodInterceptor.java | MyMethodInterceptor | invoke | class MyMethodInterceptor implements MethodInterceptor {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {<FILL_FUNCTION_BODY>}
} |
// 在方法调用之前执行的逻辑
System.out.println("Method " + invocation.getMethod().getName() + " is called.");
// 调用原始方法
Object result = invocation.proceed();
// 在方法调用之后执行的逻辑
System.out.println("Method " + invocation.getMethod().getName() + " returns " + result);
return resul... | 48 | 102 | 150 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-advice-throwsAdvice/src/main/java/com/xcs/spring/MyService.java | MyService | doSomethingException | class MyService {
public void doSomethingException() {<FILL_FUNCTION_BODY>}
} |
System.out.println("Doing something exception...");
int i = 1 / 0;
| 29 | 27 | 56 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-advice-throwsAdvice/src/main/java/com/xcs/spring/ThrowsAdviceDemo.java | ThrowsAdviceDemo | main | class ThrowsAdviceDemo {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// 创建代理工厂&创建目标对象
ProxyFactory proxyFactory = new ProxyFactory(new MyService());
// 创建通知
proxyFactory.addAdvice(new MyThrowsAdvice());
// 获取代理对象
MyService proxy = (MyService) proxyFactory.getProxy();
// 调用代理对象的方法
proxy.doSomethingException();
| 36 | 93 | 129 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-advisor/src/main/java/com/xcs/spring/AdvisorDemo.java | AdvisorDemo | main | class AdvisorDemo {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// 创建代理工厂
ProxyFactory proxyFactory = new ProxyFactory(new MyService());
// 添加Advisor
proxyFactory.addAdvisor(new MyCustomAdvisor());
// 获取代理对象
MyService proxy = (MyService) proxyFactory.getProxy();
// 调用方法
proxy.foo(); // 会触发通知
proxy.bar(); // 不会... | 34 | 106 | 140 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-advisorAdapter/src/main/java/com/xcs/spring/AdvisorAdapterDemo.java | AdvisorAdapterDemo | main | class AdvisorAdapterDemo {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// 注册自定义适配器
GlobalAdvisorAdapterRegistry.getInstance().registerAdvisorAdapter(new NullReturningAdviceAdapter());
// 创建代理工厂
ProxyFactory proxyFactory = new ProxyFactory(new MyService());
// 添加Advisor
proxyFactory.addAdvice(new MyNullReturningAdvice());
// 获取代理对象
... | 35 | 177 | 212 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-advisorAdapter/src/main/java/com/xcs/spring/MyNullReturningAdvice.java | MyNullReturningAdvice | nullReturning | class MyNullReturningAdvice implements NullReturningAdvice {
@Override
public Object nullReturning(Method method, Object[] args, Object target) throws Throwable {<FILL_FUNCTION_BODY>}
} |
System.out.println("Null Returning method " + method.getName() + " is called.");
return "hello default value";
| 57 | 34 | 91 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-advisorAdapter/src/main/java/com/xcs/spring/NullReturningAdviceInterceptor.java | NullReturningAdviceInterceptor | invoke | class NullReturningAdviceInterceptor implements MethodInterceptor, AfterAdvice {
/** 空返回通知 */
private final NullReturningAdvice advice;
/**
* 构造一个空返回通知拦截器。
* @param advice 空返回通知
*/
public NullReturningAdviceInterceptor(NullReturningAdvice advice) {
Assert.notNull(advice, "Advice... |
// 执行方法调用,获取返回值
Object retVal = mi.proceed();
// 如果返回值为空,则根据空返回通知执行后的返回值
if (retVal == null) {
retVal = this.advice.nullReturning(mi.getMethod(), mi.getArguments(), mi.getThis());
}
return retVal;
| 257 | 97 | 354 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-advisorAdapterRegistry/src/main/java/com/xcs/spring/AdvisorAdapterRegistryDemo.java | AdvisorAdapterRegistryDemo | main | class AdvisorAdapterRegistryDemo {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// 创建默认的Advisor适配器注册表实例
DefaultAdvisorAdapterRegistry registry = new DefaultAdvisorAdapterRegistry();
// 包装给定的MyMethodBeforeAdvice为Advisor
Advisor advisor = registry.wrap(new MyMethodBeforeAdvice());
// 获取Advisor中的拦截器数组
MethodInterceptor[] interceptors = registry.getInt... | 36 | 159 | 195 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-advisorChainFactory/src/main/java/com/xcs/spring/AdvisorChainFactoryDemo.java | AdvisorChainFactoryDemo | main | class AdvisorChainFactoryDemo {
public static void main(String[] args) throws NoSuchMethodException {<FILL_FUNCTION_BODY>}
} |
// 创建AOP配置对象
AdvisedSupport config = new AdvisedSupport();
// 添加前置通知
config.addAdvice(new MyMethodBeforeAdvice());
// 添加后置返回通知
config.addAdvice(new MyAfterReturningAdvice());
// 设置目标类
Class<MyService> targetClass = MyService.class;
// 获取目标方法
... | 41 | 218 | 259 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-annotationAwareAspectJAutoProxyCreator/src/main/java/com/xcs/spring/AnnotationAwareAspectJAutoProxyCreatorDemo.java | AnnotationAwareAspectJAutoProxyCreatorDemo | main | class AnnotationAwareAspectJAutoProxyCreatorDemo {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// 创建一个默认的 Bean 工厂
AnnotationConfigApplicationContext beanFactory = new AnnotationConfigApplicationContext();
// 注册AnnotationAwareAspectJAutoProxyCreator作为Bean,用于自动创建切面代理
beanFactory.registerBeanDefinition("internalAutoProxyCreator", new RootBeanDefinition(AnnotationAwareAspectJAutoProx... | 43 | 177 | 220 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-aopProxy/src/main/java/com/xcs/spring/AopProxyDemo.java | AopProxyDemo | cglibProxy | class AopProxyDemo {
public static void main(String[] args) throws Exception {
// cglibProxy();
jdkProxy();
}
/**
* cglib代理
*
* @throws Exception
*/
private static void cglibProxy() throws Exception {<FILL_FUNCTION_BODY>}
/**
* Jdk代理
*
* @throws E... |
// 创建AdvisedSupport对象,用于配置AOP代理
AdvisedSupport advisedSupport = new AdvisedSupport();
// 设置目标对象
advisedSupport.setTarget(new MyServiceImpl());
// 添加拦截器
advisedSupport.addAdvice(new MyMethodInterceptor());
// 获取CglibAopProxy的Class对象
Class<?> cglibClass = ... | 438 | 292 | 730 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-aopProxy/src/main/java/com/xcs/spring/MyMethodInterceptor.java | MyMethodInterceptor | invoke | class MyMethodInterceptor implements MethodInterceptor {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {<FILL_FUNCTION_BODY>}
} |
// 在方法调用之前执行的逻辑
System.out.println("Before " + invocation.getMethod().getName());
// 调用原始方法
Object result = invocation.proceed();
// 在方法调用之后执行的逻辑
System.out.println("After " + invocation.getMethod().getName());
return result;
| 48 | 90 | 138 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-aopProxyFactory/src/main/java/com/xcs/spring/AopProxyFactoryDemo.java | AopProxyFactoryDemo | cglibProxy | class AopProxyFactoryDemo {
public static void main(String[] args) {
// 分别演示 JDK 动态代理和 CGLIB 代理
jdkProxy();
cglibProxy();
}
/**
* JDK 动态代理示例
*/
private static void jdkProxy() {
// 创建 AdvisedSupport 对象,用于配置 AOP 代理
AdvisedSupport advisedSupport = new Adv... |
// 创建 AdvisedSupport 对象,用于配置 AOP 代理
AdvisedSupport advisedSupport = new AdvisedSupport();
// 设置目标对象
advisedSupport.setTarget(new MyServiceImpl());
// 创建 DefaultAopProxyFactory 实例
AopProxyFactory aopProxyFactory = new DefaultAopProxyFactory();
// 创建 CGLIB 代理对象
... | 301 | 154 | 455 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-aspectInstanceFactory/src/main/java/com/xcs/spring/AspectInstanceFactoryDemo.java | AspectInstanceFactoryDemo | main | class AspectInstanceFactoryDemo {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// 使用 SimpleAspectInstanceFactory 创建切面实例
SimpleAspectInstanceFactory sAif = new SimpleAspectInstanceFactory(MyAspect.class);
System.out.println("SimpleAspectInstanceFactory (1): " + sAif.getAspectInstance());
System.out.println("SimpleAspectInstanceFactory (2): " + sAif.getAspectInstanc... | 36 | 578 | 614 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-aspectJAdvisorFactory/src/main/java/com/xcs/spring/AspectJAdvisorFactoryDemo.java | AspectJAdvisorFactoryDemo | main | class AspectJAdvisorFactoryDemo {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// 创建一个默认的 Bean 工厂
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
// 在 Bean 工厂中注册一个名为 "myAspect" 的单例 Bean,类型为 MyAspect
beanFactory.registerSingleton("myAspect", new MyAspect());
// 创建一个 Aspect 实例工厂,用于实例化切面
MetadataAwareAspectInstanceFactory f... | 39 | 251 | 290 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-beanFactoryAdvisorRetrievalHelper/src/main/java/com/xcs/spring/BeanFactoryAdvisorRetrievalHelperDemo.java | BeanFactoryAdvisorRetrievalHelperDemo | main | class BeanFactoryAdvisorRetrievalHelperDemo {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// 创建一个默认的 Bean 工厂
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
// 向 Bean 工厂注册一个名为 "myAspect" 的 Advisor
beanFactory.registerSingleton("myAspect", new MyAdvisor());
// 创建 BeanFactoryAdvisorRetrievalHelper 实例,并传入 Bean 工厂
BeanFactoryAdvisorRet... | 42 | 186 | 228 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-beanFactoryAspectJAdvisorsBuilder/src/main/java/com/xcs/spring/BeanFactoryAspectJAdvisorsBuilderDemo.java | BeanFactoryAspectJAdvisorsBuilderDemo | main | class BeanFactoryAspectJAdvisorsBuilderDemo {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// 创建一个默认的 Bean 工厂
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
// 在 Bean 工厂中注册一个名为 "myAspect" 的单例 Bean,类型为 MyAspect
beanFactory.registerSingleton("myAspect", new MyAspect());
// 创建 BeanFactoryAspectJAdvisorsBuilder 实例,并传入 Bean 工厂和 ReflectiveAspect... | 42 | 219 | 261 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-cglibProxy/src/main/java/com/xcs/spring/CglibProxyDemo.java | CglibProxyDemo | main | class CglibProxyDemo {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// 创建 Enhancer 对象,用于生成代理类
Enhancer enhancer = new Enhancer();
// 设置目标对象的父类
enhancer.setSuperclass(MyServiceImpl.class);
// 设置回调拦截器
enhancer.setCallback(new MyMethodInterceptor());
// 创建代理对象
MyService proxyObject = (MyService) enhancer.create();
//... | 36 | 152 | 188 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-cglibProxy/src/main/java/com/xcs/spring/MyMethodInterceptor.java | MyMethodInterceptor | intercept | class MyMethodInterceptor implements MethodInterceptor {
@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {<FILL_FUNCTION_BODY>}
} |
System.out.println("Before invoking method: " + method.getName());
Object result = methodProxy.invokeSuper(obj, args);
System.out.println("After invoking method: " + method.getName());
return result;
| 58 | 61 | 119 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-classFilter/src/main/java/com/xcs/spring/ClassFilterDemo.java | ClassFilterDemo | main | class ClassFilterDemo {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// 创建 AnnotationClassFilter 实例,匹配带有 MyAnnotation 注解的类
ClassFilter filter1 = new AnnotationClassFilter(MyAnnotation.class);
System.out.println("AnnotationClassFilter 是否匹配 MyService 类:" + filter1.matches(MyService.class));
// 创建 TypePatternClassFilter 实例,匹配指定类名的类
ClassFilter filt... | 33 | 341 | 374 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-enableAspectJAutoProxy/src/main/java/com/xcs/spring/EnableAspectJAutoProxyDemo.java | EnableAspectJAutoProxyDemo | main | class EnableAspectJAutoProxyDemo {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// 创建基于注解的应用上下文
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
// 从应用上下文中获取FooService bean
FooService fooService = context.getBean(FooService.class);
// 调用FooService的方法
fooService.foo();
| 38 | 86 | 124 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-enableLoadTimeWeaving/src/main/java/com/xcs/spring/EnableLoadTimeWeavingDemo.java | EnableLoadTimeWeavingDemo | main | class EnableLoadTimeWeavingDemo {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
FooService fooService = context.getBean(FooService.class);
fooService.foo();
// 换行
System.out.println();
FooService fooService1 = new FooService();
fooService1.f... | 37 | 86 | 123 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-enableLoadTimeWeaving/src/main/java/com/xcs/spring/MyLTWAspect.java | MyLTWAspect | around | class MyLTWAspect {
@Around("ltwPointcut()")
public Object around(ProceedingJoinPoint pjp) throws Throwable {<FILL_FUNCTION_BODY>}
@Pointcut("execution(public * com.xcs.spring.FooService.*(..))")
public void ltwPointcut(){}
} |
// 在方法调用之前执行的逻辑
System.out.println("Method " + pjp.getSignature().getName() + " is called.");
// 调用原始方法
Object result = pjp.proceed();
// 在方法调用之后执行的逻辑
System.out.println("Method " + pjp.getSignature().getName() + " returns " + result);
return result;
| 91 | 105 | 196 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-jdkProxy/src/main/java/com/xcs/spring/JdkProxyDemo.java | JdkProxyDemo | main | class JdkProxyDemo {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// 创建目标对象
MyService target = new MyServiceImpl();
// 获取目标对象的类对象
Class clz = target.getClass();
// 创建代理对象,并指定目标对象的类加载器、实现的接口以及调用处理器
MyService proxyObject = (MyService) Proxy.newProxyInstance(clz.getClassLoader(), clz.getInterfaces(), new MyInvocationHandler(target));
... | 35 | 172 | 207 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-jdkProxy/src/main/java/com/xcs/spring/MyInvocationHandler.java | MyInvocationHandler | invoke | class MyInvocationHandler implements InvocationHandler {
private Object target;
public MyInvocationHandler(Object target) {
this.target = target;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {<FILL_FUNCTION_BODY>}
} |
System.out.println("Before method execution");
Object result = method.invoke(target, args);
System.out.println("After method execution");
return result;
| 82 | 45 | 127 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-metadataAwareAspectInstanceFactory/src/main/java/com/xcs/spring/MetadataAwareAspectInstanceFactoryDemo.java | MetadataAwareAspectInstanceFactoryDemo | main | class MetadataAwareAspectInstanceFactoryDemo {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// 使用 SimpleMetadataAwareAspectInstanceFactory 实例化切面
SimpleMetadataAwareAspectInstanceFactory simpleMetadataAwareAif = new SimpleMetadataAwareAspectInstanceFactory(MyAspect.class, "myAspect");
System.out.println("SimpleMetadataAwareAspectInstanceFactory (1) = " + simpleMetadataAwareAif.getAspec... | 40 | 783 | 823 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-methodMatcher/src/main/java/com/xcs/spring/MethodMatcherDemo.java | MethodMatcherDemo | main | class MethodMatcherDemo {
public static void main(String[] args) throws Exception {<FILL_FUNCTION_BODY>}
} |
// 使用 AnnotationMethodMatcher 检查是否具有特定注解
AnnotationMethodMatcher methodMatcher = new AnnotationMethodMatcher(MyAnnotation.class);
System.out.println("方法是否具有特定注解: " + methodMatcher.matches(MyService.class.getDeclaredMethod("myMethod"), MyService.class));
// 使用 AspectJExpressionPointcut ... | 37 | 401 | 438 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-pointcut/src/main/java/com/xcs/spring/MyCustomPointcut.java | MyCustomPointcut | getMethodMatcher | class MyCustomPointcut implements Pointcut {
@Override
public ClassFilter getClassFilter() {
// 匹配所有类
return clazz -> true;
}
@Override
public MethodMatcher getMethodMatcher() {<FILL_FUNCTION_BODY>}
} |
return new MethodMatcher() {
@Override
public boolean matches(Method method, Class<?> targetClass) {
// 匹配所有以 "get" 开头的方法
return method.getName().startsWith("get");
}
@Override
public boolean isRuntime() {
... | 76 | 151 | 227 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-pointcut/src/main/java/com/xcs/spring/PointcutDemo.java | PointcutDemo | aspectJExpressionPointcut | class PointcutDemo {
public static void main(String[] args) {
customPointcut();
}
/**
* 自定义 Pointcut 最佳实践
*/
private static void customPointcut() {
// 创建代理工厂
ProxyFactory proxyFactory = new ProxyFactory(new MyBean());
// 添加切面:使用自定义的切入点和通知构建默认切面
proxyFac... |
// 创建 AspectJ 表达式切入点
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
pointcut.setExpression("execution(* *.getName())");
// 创建代理工厂
ProxyFactory proxyFactory = new ProxyFactory(new MyBean());
// 添加切面:使用自定义的切入点和通知构建默认切面
proxyFactory.addAdviso... | 704 | 210 | 914 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-proxyFactory/src/main/java/com/xcs/spring/MyMethodBeforeAdvice.java | MyMethodBeforeAdvice | before | class MyMethodBeforeAdvice implements MethodBeforeAdvice {
@Override
public void before(Method method, Object[] args, Object target) throws Throwable {<FILL_FUNCTION_BODY>}
} |
System.out.println("Before method " + method.getName() + " is called.");
| 52 | 24 | 76 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-proxyFactory/src/main/java/com/xcs/spring/ProxyFactoryDemo.java | ProxyFactoryDemo | main | class ProxyFactoryDemo {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// 创建代理工厂&创建目标对象
ProxyFactory proxyFactory = new ProxyFactory(new MyService());
// 创建通知
proxyFactory.addAdvice(new MyMethodBeforeAdvice());
// 获取代理对象
Object proxy = proxyFactory.getProxy();
// 调用代理对象的方法
System.out.println("proxy = " + proxy.getClass());
... | 35 | 97 | 132 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-targetSource/src/main/java/com/xcs/spring/ConnectionPoolTargetSource.java | ConnectionPoolTargetSource | initializeConnectionPool | class ConnectionPoolTargetSource implements TargetSource {
/**
* 连接池
*/
private final BlockingQueue<MyConnection> connectionPool;
/**
* 构造函数,初始化连接池。
*
* @param poolSize 连接池大小
*/
public ConnectionPoolTargetSource(int poolSize) {
this.connectionPool = new ArrayBlock... |
for (int i = 0; i < poolSize; i++) {
MyConnection connection = new MyConnection("Connection" + i);
connectionPool.offer(connection);
}
| 455 | 49 | 504 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-targetSource/src/main/java/com/xcs/spring/MyConnection.java | MyConnection | toString | class MyConnection {
private String name;
public MyConnection(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {<FILL_FUNCTION_BODY>}
} |
return "MyConnection{" +
"name='" + name + '\'' +
'}';
| 101 | 28 | 129 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aop/spring-aop-targetSource/src/main/java/com/xcs/spring/TargetSourceDemo.java | TargetSourceDemo | main | class TargetSourceDemo {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// 创建代理工厂
ProxyFactory proxyFactory = new ProxyFactory();
// 设置目标源为连接池目标源,连接池大小为3
proxyFactory.setTargetSource(new ConnectionPoolTargetSource(3));
// 获取代理对象
MyConnection proxy = (MyConnection) proxyFactory.getProxy();
// 调用10次方法
for (int i = 0; i < 10; i... | 34 | 131 | 165 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aware/spring-aware-applicationEventPublisherAware/src/main/java/com/xcs/spring/ApplicationEventPublisherAwareApplication.java | ApplicationEventPublisherAwareApplication | main | class ApplicationEventPublisherAwareApplication {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfiguration.class);
MyApplicationEventPublisherAware publisherAware = context.getBean(MyApplicationEventPublisherAware.class);
publisherAware.publish("hello world");
| 37 | 64 | 101 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aware/spring-aware-applicationStartupAware/src/main/java/com/xcs/spring/ApplicationStartupAwareApplication.java | ApplicationStartupAwareApplication | main | class ApplicationStartupAwareApplication {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.setApplicationStartup(new BufferingApplicationStartup(100));
context.register(MyConfiguration.class);
context.refresh();
context.close();
| 36 | 63 | 99 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aware/spring-aware-applicationStartupAware/src/main/java/com/xcs/spring/config/MyApplicationStartupAware.java | MyApplicationStartupAware | afterPropertiesSet | class MyApplicationStartupAware implements ApplicationStartupAware, InitializingBean {
private ApplicationStartup applicationStartup;
@Override
public void setApplicationStartup(ApplicationStartup applicationStartup) {
this.applicationStartup = applicationStartup;
}
@Override
public v... |
StartupStep step1 = applicationStartup.start("MyApplicationStartupAware Logic Step 1");
// 自定义逻辑
Thread.sleep(200);
step1.tag("status", "done").end();
StartupStep step2 = applicationStartup.start("MyApplicationStartupAware Logic Step 2");
// 自定义逻辑
Thread.sleep(3... | 97 | 120 | 217 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aware/spring-aware-beanClassLoaderAware/src/main/java/com/xcs/spring/BeanClassLoaderAwareApplication.java | BeanClassLoaderAwareApplication | main | class BeanClassLoaderAwareApplication {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfiguration.class);
MyBeanClassLoaderAware myBeanClassLoaderAware = context.getBean(MyBeanClassLoaderAware.class);
myBeanClassLoaderAware.loadAndExecute();
| 37 | 66 | 103 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aware/spring-aware-beanClassLoaderAware/src/main/java/com/xcs/spring/config/MyBeanClassLoaderAware.java | MyBeanClassLoaderAware | loadAndExecute | class MyBeanClassLoaderAware implements BeanClassLoaderAware {
private ClassLoader classLoader;
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
}
public void loadAndExecute() {<FILL_FUNCTION_BODY>}
} |
try {
Class<?> clazz = classLoader.loadClass("com.xcs.spring.service.UserServiceImpl");
UserServiceImpl instance = (UserServiceImpl) clazz.getDeclaredConstructor().newInstance();
System.out.println("UserInfo = " + instance.getUserInfo());
} catch (Exception e) {
... | 82 | 97 | 179 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aware/spring-aware-beanFactoryAware/src/main/java/com/xcs/spring/BeanFactoryAwareApplication.java | BeanFactoryAwareApplication | main | class BeanFactoryAwareApplication {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfiguration.class);
UserService userService = context.getBean(UserService.class);
userService.validateUser("root", "123456");
| 36 | 59 | 95 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aware/spring-aware-beanFactoryAware/src/main/java/com/xcs/spring/service/UserService.java | UserService | validateUser | class UserService implements BeanFactoryAware, InitializingBean {
private BeanFactory beanFactory;
private UserValidator userValidator;
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
}
@Override
public void aft... |
boolean success = userValidator.validate(username, password);
if (success){
System.out.println("验证账号密码成功");
}else{
System.out.println("验证账号密码失败");
}
| 192 | 63 | 255 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aware/spring-aware-beanFactoryAware/src/main/java/com/xcs/spring/validate/ComplexUserValidator.java | ComplexUserValidator | validate | class ComplexUserValidator implements UserValidator {
@Override
public boolean validate(String username, String password) {<FILL_FUNCTION_BODY>}
} |
System.out.println("使用ComplexUserValidator");
return username != null && username.length() > 5 && password != null && password.length() > 8;
| 41 | 44 | 85 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aware/spring-aware-beanFactoryAware/src/main/java/com/xcs/spring/validate/SimpleUserValidator.java | SimpleUserValidator | validate | class SimpleUserValidator implements UserValidator {
@Override
public boolean validate(String username, String password) {<FILL_FUNCTION_BODY>}
} |
System.out.println("使用SimpleUserValidator");
return username != null && password != null;
| 40 | 29 | 69 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aware/spring-aware-beanNameAware/src/main/java/com/xcs/spring/service/MyBasePayService.java | MyBasePayService | destroy | class MyBasePayService implements BeanNameAware, InitializingBean, DisposableBean {
private String beanName;
@Override
public void setBeanName(String beanName) {
this.beanName = beanName;
}
@Override
public void afterPropertiesSet() throws Exception {
System.out.println("Modul... |
System.out.println("Module " + beanName + " has been unregistered.");
| 127 | 24 | 151 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aware/spring-aware-embeddedValueResolverAware/src/main/java/com/xcs/spring/EmbeddedValueResolverAwareApplication.java | EmbeddedValueResolverAwareApplication | main | class EmbeddedValueResolverAwareApplication {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfiguration.class);
MyEmbeddedValueResolverAware resolverAware = context.getBean(MyEmbeddedValueResolverAware.class);
resolverAware.resolve();
| 38 | 66 | 104 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aware/spring-aware-embeddedValueResolverAware/src/main/java/com/xcs/spring/config/MyEmbeddedValueResolverAware.java | MyEmbeddedValueResolverAware | resolve | class MyEmbeddedValueResolverAware implements EmbeddedValueResolverAware {
private StringValueResolver stringValueResolver;
@Override
public void setEmbeddedValueResolver(StringValueResolver resolver) {
this.stringValueResolver = resolver;
}
public void resolve() {<FILL_FUNCTION_BODY>}
} |
String resolvedValue = stringValueResolver.resolveStringValue("Hello, ${user.name:xcs}! Today is #{T(java.time.LocalDate).now().toString()}");
System.out.println(resolvedValue);
| 91 | 59 | 150 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aware/spring-aware-environmentAware/src/main/java/com/xcs/spring/EnvironmentAwareApplication.java | EnvironmentAwareApplication | main | class EnvironmentAwareApplication {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfiguration.class);
MyEnvironmentAware environmentAware = context.getBean(MyEnvironmentAware.class);
System.out.println("AppProperty = " + environmentAware.getAppProperty());
| 34 | 67 | 101 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aware/spring-aware-importAware/src/main/java/com/xcs/spring/ImportAwareApplication.java | ImportAwareApplication | main | class ImportAwareApplication {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfiguration.class);
String customBean = context.getBean(String.class);
System.out.println(customBean);
| 34 | 50 | 84 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aware/spring-aware-importAware/src/main/java/com/xcs/spring/config/MyImportAware.java | MyImportAware | setImportMetadata | class MyImportAware implements ImportAware {
private AnnotationAttributes enableXcs;
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {<FILL_FUNCTION_BODY>}
@Bean
public String customBean() {
return "This is a custom bean!";
}
} |
this.enableXcs = AnnotationAttributes.fromMap(
importMetadata.getAnnotationAttributes(EnableXcs.class.getName(), false));
if (this.enableXcs == null) {
throw new IllegalArgumentException(
"@EnableXcs is not present on importing class " + importMetadata.ge... | 82 | 83 | 165 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aware/spring-aware-messageSourceAware/src/main/java/com/xcs/spring/MessageSourceAwareApplication.java | MessageSourceAwareApplication | main | class MessageSourceAwareApplication {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfiguration.class);
MyMessageSourceAware messageSourceAware = context.getBean(MyMessageSourceAware.class);
messageSourceAware.getMessage();
| 35 | 58 | 93 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aware/spring-aware-resourceLoaderAware/src/main/java/com/xcs/spring/ResourceLoaderAwareApplication.java | ResourceLoaderAwareApplication | main | class ResourceLoaderAwareApplication {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfiguration.class);
MyResourceLoaderAware resourceLoaderAware = context.getBean(MyResourceLoaderAware.class);
resourceLoaderAware.getResource("classpath:xcs.txt");
| 35 | 67 | 102 | <no_super_class> |
xuchengsheng_spring-reading | spring-reading/spring-aware/spring-aware-resourceLoaderAware/src/main/java/com/xcs/spring/config/MyResourceLoaderAware.java | MyResourceLoaderAware | getResource | class MyResourceLoaderAware implements ResourceLoaderAware {
private ResourceLoader resourceLoader;
@Override
public void setResourceLoader(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}
public void getResource(String location){<FILL_FUNCTION_BODY>}
} |
try {
Resource resource = resourceLoader.getResource(location);
System.out.println("Resource content: " + new String(FileCopyUtils.copyToByteArray(resource.getInputStream())));
} catch (IOException e) {
e.printStackTrace();
}
| 79 | 71 | 150 | <no_super_class> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.