WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions koupleless-base-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
<version>${sofa.ark.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.koupleless.plugin.context;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
import org.springframework.boot.web.reactive.context.StandardReactiveWebEnvironment;
import org.springframework.core.env.ConfigurablePropertyResolver;
import org.springframework.core.env.MutablePropertySources;

/**
* copy from {@link org.springframework.boot.web.reactive.context.ApplicationReactiveWebEnvironment}
* due to not public class
* {@link StandardReactiveWebEnvironment} for typical use in a typical
* {@link SpringApplication}.
*
* @author Phillip Webb
*/
class ApplicationReactiveWebEnvironment extends StandardReactiveWebEnvironment {

@Override
protected String doGetActiveProfilesProperty() {
return null;
}

@Override
protected String doGetDefaultProfilesProperty() {
return null;
}

@Override
protected ConfigurablePropertyResolver createPropertyResolver(MutablePropertySources propertySources) {
return ConfigurationPropertySources.createPropertyResolver(propertySources);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.koupleless.plugin.context;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
import org.springframework.core.env.ConfigurablePropertyResolver;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.web.context.support.StandardServletEnvironment;

/**
* copy from {@link org.springframework.boot.web.reactive.context.ApplicationServletEnvironment}
* due to not public class
* {@link StandardServletEnvironment} for typical use in a typical
* {@link SpringApplication}.
*
* @author Phillip Webb
*/
class ApplicationServletEnvironment extends StandardServletEnvironment {

@Override
protected String doGetActiveProfilesProperty() {
return null;
}

@Override
protected String doGetDefaultProfilesProperty() {
return null;
}

@Override
protected ConfigurablePropertyResolver createPropertyResolver(MutablePropertySources propertySources) {
return ConfigurationPropertySources.createPropertyResolver(propertySources);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.koupleless.plugin.context;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.ApplicationContextFactory;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext;
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;

/**
* 目的是自定义 beanFactory 的销毁行为
*
* @author duanzhiqiang
* @version BizAnnotationConfigReactiveWebServerApplicationContext.java, v 0.1 2024年11月08日 16:23 duanzhiqiang
*/
public class BizAnnotationConfigReactiveWebServerApplicationContext extends
AnnotationConfigReactiveWebServerApplicationContext {
/**
* 构造器
*
* @param beanFactory 指定的beanFactory
*/
public BizAnnotationConfigReactiveWebServerApplicationContext(DefaultListableBeanFactory beanFactory) {
super(beanFactory);
}

/**
* 替换上下文创建行为利用 spring boot factories 扩展 并在默认的优先级前
* {@link ApplicationContextFactory} registered in {@code spring.factories} to support
* {@link AnnotationConfigServletWebServerApplicationContext}.
*/
static class Factory implements ApplicationContextFactory, Ordered {

@Override
public Class<? extends ConfigurableEnvironment> getEnvironmentType(WebApplicationType webApplicationType) {
return (webApplicationType != WebApplicationType.REACTIVE) ? null
: ApplicationReactiveWebEnvironment.class;
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Undefined class ApplicationReactiveWebEnvironment

The class ApplicationReactiveWebEnvironment is referenced in methods getEnvironmentType and createEnvironment but is not imported or defined in the provided code. This will lead to compilation errors.

Ensure that ApplicationReactiveWebEnvironment is properly defined and imported.

Also applies to: 60-61

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gentten, thank you for removing the undefined reference to ApplicationReactiveWebEnvironment.


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

}

@Override
public ConfigurableEnvironment createEnvironment(WebApplicationType webApplicationType) {
return (webApplicationType != WebApplicationType.REACTIVE) ? null
: new ApplicationReactiveWebEnvironment();
}

@Override
public ConfigurableApplicationContext create(WebApplicationType webApplicationType) {
return (webApplicationType != WebApplicationType.REACTIVE) ? null : createContext();
}

/**
* 创建上下文
*
* @return 上下文
*/
private ConfigurableApplicationContext createContext() {
//自定义BeanFactory的销毁
DefaultListableBeanFactory beanFactory = new BizDefaultListableBeanFactory();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Undefined class BizDefaultListableBeanFactory

At line 76, BizDefaultListableBeanFactory is instantiated but not imported or defined in the current context, which may cause compilation issues.

Make sure that BizDefaultListableBeanFactory is defined and imported correctly.

return new BizAnnotationConfigReactiveWebServerApplicationContext(beanFactory);
}

@Override
public int getOrder() {
return Ordered.HIGHEST_PRECEDENCE;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.koupleless.plugin.context;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.ApplicationContextFactory;
import org.springframework.boot.WebApplicationType;

import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;

/**
* 目的是自定义 beanFactory 的销毁行为
*
* @author duanzhiqiang
* @version BizAnnotationConfigServletWebServerApplicationContext.java, v 0.1 2024年11月08日 16:23 duanzhiqiang
*/
public class BizAnnotationConfigServletWebServerApplicationContext extends
AnnotationConfigServletWebServerApplicationContext {
/**
* 构造器
*
* @param beanFactory 指定的beanFactory
*/
public BizAnnotationConfigServletWebServerApplicationContext(DefaultListableBeanFactory beanFactory) {
super(beanFactory);
}

@Override
public Object getBean(String name) throws BeansException {
return super.getBean(name);
}

@Override
public <T> T getBean(Class<T> requiredType, Object... args) throws BeansException {
return super.getBean(requiredType, args);
}

/**
* 替换上下文创建行为利用 spring boot factories 扩展 并在默认的优先级前
* {@link ApplicationContextFactory} registered in {@code spring.factories} to support
* {@link AnnotationConfigServletWebServerApplicationContext}.
*/
static class Factory implements ApplicationContextFactory, Ordered {

@Override
public Class<? extends ConfigurableEnvironment> getEnvironmentType(WebApplicationType webApplicationType) {
return (webApplicationType != WebApplicationType.SERVLET) ? null
: ApplicationServletEnvironment.class;
}
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure 'ApplicationServletEnvironment' is Defined and Imported

The class ApplicationServletEnvironment is used but not imported. If this is a custom class, please ensure it is properly defined and imported to avoid compilation errors.

Apply this diff to add the necessary import statement:

+import org.springframework.boot.context.ApplicationServletEnvironment;

Also applies to: 71-73

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gentten, thank you for resolving the issue with ApplicationServletEnvironment!


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!


@Override
public ConfigurableEnvironment createEnvironment(WebApplicationType webApplicationType) {
return (webApplicationType != WebApplicationType.SERVLET) ? null
: new ApplicationServletEnvironment();
}

@Override
public ConfigurableApplicationContext create(WebApplicationType webApplicationType) {
return (webApplicationType != WebApplicationType.SERVLET) ? null : createContext();
}

/**
* 创建上下文
*
* @return 上下文
*/
private ConfigurableApplicationContext createContext() {
//自定义BeanFactory的销毁
DefaultListableBeanFactory beanFactory = new BizDefaultListableBeanFactory();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure 'BizDefaultListableBeanFactory' is Defined and Imported

The class BizDefaultListableBeanFactory is used but not imported. If this is a custom class, please ensure it is properly defined and imported to avoid compilation errors.

Apply this diff to add the necessary import statement:

+import com.alipay.sofa.koupleless.plugin.context.BizDefaultListableBeanFactory;

Committable suggestion skipped: line range outside the PR's diff.

return new BizAnnotationConfigServletWebServerApplicationContext(beanFactory);
}

@Override
public int getOrder() {
return HIGHEST_PRECEDENCE;
}
}

}
Loading