-
Notifications
You must be signed in to change notification settings - Fork 14
add MultiBizProperties assert in web sample #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe changes involve modifications to three application classes: Changes
Possibly related PRs
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
- springboot-samples/web/tomcat/base-web-single-host/base-web-single-host-bootstrap/src/main/java/com/alipay/sofa/web/base/BaseApplication.java (1 hunks)
- springboot-samples/web/tomcat/biz1-web-single-host/src/main/java/com/alipay/sofa/web/biz1/Biz1Application.java (1 hunks)
- springboot-samples/web/tomcat/biz2-web-single-host/src/main/java/com/alipay/sofa/web/biz2/Biz2Application.java (1 hunks)
🧰 Additional context used
🔇 Additional comments (5)
springboot-samples/web/tomcat/biz1-web-single-host/src/main/java/com/alipay/sofa/web/biz1/Biz1Application.java (2)
23-23: LGTM! Appropriate use of Spring's Assert utility.Using Spring's Assert is a good choice for configuration validation in a Spring Boot application.
31-32: 🛠️ Refactor suggestionConsider using Spring's configuration properties instead of System properties.
While the validation is good for ensuring correct module identity, using System properties for configuration has some drawbacks:
- System properties are global and mutable
- Spring Boot provides better alternatives through
@ConfigurationPropertiesorapplication.properties/yamlConsider refactoring to use Spring's configuration mechanism:
-System.setProperty("app.name", "biz1"); -Assert.isTrue("biz1".equals(System.getProperty("app.name")), "app.name is not biz1"); +@Value("${app.name:}") +private String appName; + +@PostConstruct +public void validateAppName() { + Assert.isTrue("biz1".equals(appName), "app.name is not biz1"); +}Then define in
application.properties:app.name=biz1Let's check if this property is used elsewhere in the codebase:
springboot-samples/web/tomcat/biz2-web-single-host/src/main/java/com/alipay/sofa/web/biz2/Biz2Application.java (1)
23-23: LGTM!The Spring Assert utility import is appropriate for the new validation logic.
springboot-samples/web/tomcat/base-web-single-host/base-web-single-host-bootstrap/src/main/java/com/alipay/sofa/web/base/BaseApplication.java (2)
25-25: LGTM!The Spring Assert utility import is appropriate for the validation being added.
33-35: Verify the impact of MultiBizProperties.initSystem() on app.name property.Let's verify if MultiBizProperties.initSystem() affects the app.name property and if this property is used elsewhere in the codebase.
✅ Verification successful
Let me generate additional scripts to check the implementation of MultiBizProperties.initSystem() to understand its impact on app.name property.
Based on the results, I can now provide a final response as we have enough information about how app.name is used across the applications.
Setting app.name property after MultiBizProperties.initSystem() is correct and necessary
The verification shows that:
- BaseApplication sets app.name to "base"
- Biz1Application sets its own app.name to "biz1"
- Biz2Application explicitly relies on the "base" value from BaseApplication
- The order of property setting in BaseApplication (MultiBizProperties.initSystem() followed by setting app.name) is correct as:
- Biz2Application's behavior confirms that BaseApplication's app.name setting should persist
- Setting it after MultiBizProperties.initSystem() ensures the property isn't overwritten
The current implementation maintains the expected behavior across all applications in the multi-application setup.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Check if MultiBizProperties.initSystem() sets or modifies app.name ast-grep --pattern 'MultiBizProperties.initSystem()' -A 10 # Check for other usages of app.name property rg -l "app\.name" # Check for property definitions in configuration files fd -e properties -e yaml -e yml | xargs rg "app\.name"Length of output: 5661
Script:
#!/bin/bash # Find and show the implementation of MultiBizProperties class ast-grep --pattern 'class MultiBizProperties { $$$ }' # Check the content of other files that use app.name cat springboot-samples/web/tomcat/biz1-web-single-host/src/main/java/com/alipay/sofa/web/biz1/Biz1Application.java cat springboot-samples/web/tomcat/biz2-web-single-host/src/main/java/com/alipay/sofa/web/biz2/Biz2Application.javaLength of output: 3806
| // System.setProperty("app.name", "biz2"); | ||
| // if not set app.name, use value "base" from base application | ||
| Assert.isTrue("base".equals(System.getProperty("app.name")), "app.name is not biz2"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Based on the shell script results, I can now generate a final response as the verification is complete. The results show clear patterns of app.name usage across different applications:
The app.name assertion is incorrect and needs to be fixed
Looking at the codebase patterns:
- BaseApplication explicitly sets and verifies app.name as "base"
- Biz1Application explicitly sets and verifies app.name as "biz1"
- Biz2Application is inconsistent with this pattern - it's trying to verify "base" while the error message expects "biz2"
The commented code should be uncommented and the assertion should be updated to match the pattern seen in other applications:
System.setProperty("app.name", "biz2");
Assert.isTrue("biz2".equals(System.getProperty("app.name")), "app.name is not biz2");🔗 Analysis chain
Please clarify the expected app.name value and fix inconsistencies.
There are several inconsistencies in the app.name validation:
- The assertion checks for "base" but the error message says "app.name is not biz2"
- The commented code suggests setting app.name to "biz2"
- The comment indicates falling back to "base", but it's unclear if this is the intended behavior
This creates confusion about whether this application should use "base" or "biz2" as its app.name.
Let's check how other applications handle this:
Please clarify:
- What should be the correct app.name value for Biz2Application?
- Should we update the error message or the assertion condition?
- Should the commented code for setting app.name be removed or uncommented?
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check app.name handling across other application classes
# Expected: Find patterns of app.name usage to understand the intended behavior
# Search for app.name related code in other application classes
rg -l "app\.name" | grep -i "application\.java" | xargs rg "app\.name" -B 2 -A 2
Length of output: 3321
| System.setProperty("app.name", "base"); | ||
| Assert.isTrue("base".equals(System.getProperty("app.name")), "app.name is not base"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider extracting "base" as a constant.
The hardcoded string "base" is used multiple times. Consider extracting it as a class constant for better maintainability and to avoid typos.
public class BaseApplication {
private static Logger LOGGER = LoggerFactory.getLogger(BaseApplication.class);
+ private static final String APP_NAME = "base";
public static void main(String[] args) {
MultiBizProperties.initSystem();
- System.setProperty("app.name", "base");
- Assert.isTrue("base".equals(System.getProperty("app.name")), "app.name is not base");
+ System.setProperty("app.name", APP_NAME);
+ Assert.isTrue(APP_NAME.equals(System.getProperty("app.name")),
+ String.format("Expected app.name to be '%s' but was '%s'", APP_NAME, System.getProperty("app.name")));📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| System.setProperty("app.name", "base"); | |
| Assert.isTrue("base".equals(System.getProperty("app.name")), "app.name is not base"); | |
| private static Logger LOGGER = LoggerFactory.getLogger(BaseApplication.class); | |
| private static final String APP_NAME = "base"; | |
| public static void main(String[] args) { | |
| MultiBizProperties.initSystem(); | |
| System.setProperty("app.name", APP_NAME); | |
| Assert.isTrue(APP_NAME.equals(System.getProperty("app.name")), | |
| String.format("Expected app.name to be '%s' but was '%s'", APP_NAME, System.getProperty("app.name"))); |
Summary by CodeRabbit
New Features
app.namesystem property is correctly set for each application.Bug Fixes