Open Closed

微服务语言包资源未加载及网页会自动刷新回首页问题 #10180


User avatar
0
2250368121 created
  • Steps to reproduce the issue:
  • 请问 我添加的微服务经常会出现语言包未加载的问题如图所示 我有一个BaseSetService的服务 在语言文本的资源中找不到,过段时间又会加载出来,我想知道语言资源包加载是通过那个服务加载的,另外我们还发现系统会在每过45分钟左右网页自动刷新一次而回到网页的首页上,无论是否在操作中还是无动作的情况下

21 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    1. Solution
    • How ABP loads localization in a microservice solution
      • In the microservice template, the Administration (or LanguageService if dynamic localization is enabled) microservice aggregates localization. All UI/apps get texts from the Application Localization endpoint via the gateway:
        • GET /api/abp/application-localization?cultureName=xx
      • Each microservice defines its own resources (e.g., BaseSetServiceResource) in its contracts/domain and registers them on startup. The Language Management infrastructure persists/serves these resources to the Administration service, which then responds to the endpoint above.
      • If a resource intermittently “disappears” from the Language Texts page or from the dropdown, check:
        1. The microservice hosting that resource is running and has started successfully.
        2. The resource assembly is referenced by the microservice host and the resource is added in the module class, for example:
    [DependsOn(/* ... */)]
          public class QRSPCBaseSetServiceDomainSharedModule : AbpModule
          {
              public override void ConfigureServices(ServiceConfigurationContext context)
              {
                  Configure<AbpLocalizationOptions>(options =>
                  {
                      options.Resources
                          .Add<BaseSetServiceResource>("en")
                          .AddBaseTypes(typeof(AbpValidationResource))
                          .AddVirtualJson("/Localization/BaseSetService"); // folder with zh-Hans.json etc.
                  });
              }
          }
    
    3) The gateway routes /api/abp/application-localization to Administration and no cache inconsistency exists (see next).
    4) If dynamic localization is enabled, ensure the Language Management DB contains the resource (initial registration occurs on first start of the resource-owning service). Restarting the service re-registers resources if needed.
    
    • Caching considerations for intermittent missing resources

      • The application-localization response is cached by clients while the backend reads from the Language Management store. In clustered deployments, use a distributed cache (e.g., Redis) for consistent results across instances. If you see intermittent visibility:
        • Ensure all services (including Administration) share the same distributed cache and database.
        • After deploying a new service or changing localization files, recycle the Administration service and clear distributed cache to avoid stale entries.
        • Verify the gateway and Administration instances are healthy; a failing instance behind load-balancer may respond without the new resource.
    • Why the page returns to Home every ~45 minutes

      • This is almost always due to authentication/session validation rather than localization. Two common causes:
        1. Security stamp validation/sign-in cookie validation cycle (for MVC/Angular with OpenIddict/Identity). If the cookie expires or security-stamp validation fails, the UI is redirected to re-authenticate, which brings the app back to its root.
        2. Access token expiry/refresh failure in SPA: if the token expires and refresh does not happen (or fails), the app reloads and lands on the root.
      • What to check:
        • Token lifetimes and cookie expiration/SlidingExpiration in your Auth Server configuration. Make sure the Angular/MVC client refreshes tokens correctly and that the allowed clock skew and refresh token settings are configured.
        • If running behind a gateway, ensure the issuer configuration (AuthServer:Authority) is correct for all services so validation doesn’t fail when tokens rotate.
        • Confirm data protection keys are persisted and shared across instances, otherwise cookies become invalid after key rotation and users get logged out periodically.
    • Diagnostics checklist

      1. Call, via the gateway, while the problem occurs:
        • GET /api/abp/application-localization?cultureName=zh-Hans&onlyDynamics=false
        • Confirm “resources” includes your BaseSetService resource name.
      2. Inspect the Administration service logs when the resource is missing; you should see the resource registration on the service startup. If not, verify the module configuration and that the assembly with localization files is loaded by the host.
      3. Ensure your JSON files are embedded/virtual (Virtual File System) and the path in AddVirtualJson matches the folder name.
      4. Verify distributed cache and DB connection strings are the same across all instances.
      5. For the 45-minute refresh:
        • Check token/cookie lifetimes in the Auth Server and whether the SPA is performing silent refresh. If necessary, increase lifetimes to confirm the behavior changes, then tune properly.
    1. Sources
    • https://abp.io/docs/latest/framework/architecture/modularity/basics
    • https://abp.io/docs/latest/framework/api-development/standard-apis/localization
    • https://abp.io/docs/latest/framework/fundamentals/localization
    • https://abp.io/docs/latest/solution-templates/microservice/localization-system

    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    你好

    请分享下你的整个解决方案的项目结构

    谢谢

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    你可以检查下数据库的LocalizationResources表.

    另外BaseSetService是否直接或者间接依赖了LanguageManagementDomainModule?

  • User Avatar
    0
    2250368121 created

    您好!这是我排查及现有的项目结构 麻烦您帮忙看看 这是 BaseSetService 的Module 看上去没有直接引用 LanguageManagementDomainModule, using Localization.Resources.AbpUi; using QRSPC.BaseSetService.Localization; using Volo.Abp.Application; using Volo.Abp.Authorization; using Volo.Abp.Commercial.SuiteTemplates; using Volo.Abp.Domain; using Volo.Abp.Http.Client; using Volo.Abp.Localization; using Volo.Abp.Localization.ExceptionHandling; using Volo.Abp.Modularity; using Volo.Abp.UI; using Volo.Abp.Validation; using Volo.Abp.Validation.Localization; using Volo.Abp.VirtualFileSystem;

    namespace QRSPC.BaseSetService;

    [DependsOn( typeof(AbpValidationModule), typeof(AbpUiModule), typeof(AbpAuthorizationAbstractionsModule), typeof(VoloAbpCommercialSuiteTemplatesModule), typeof(AbpDddApplicationContractsModule), typeof(AbpDddDomainSharedModule) )] public class QRSPCBaseSetServiceContractsModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { Configure<AbpVirtualFileSystemOptions>(options => { options.FileSets.AddEmbedded<QRSPCBaseSetServiceContractsModule>(); });

        Configure&lt;AbpLocalizationOptions&gt;(options =>
        {
            options.Resources
                .Add&lt;BaseSetServiceResource&gt;("en")
                .AddBaseTypes(typeof(AbpValidationResource), typeof(AbpUiResource))
                .AddVirtualJson("/Localization/BaseSetService");
        });
    
        Configure&lt;AbpExceptionLocalizationOptions&gt;(options =>
        {
            options.MapCodeNamespace("BaseSetService", typeof(BaseSetServiceResource));
        });
    }
    

    } ,另外 检查过数据库 当语言文本管理 资源中不存在BaseSetService的资源时数据库数据也是没有的, 这是我的解决方案的结构

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    数据库的LocalizationResources和LocalizationTexts表有BaseSetService的本地化数据吗?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    这是 BaseSetService 的Module 看上去没有直接引用 LanguageManagementDomainModule

    它可能是间接引用的, 请看看它依赖的模块尤其是administration

  • User Avatar
    0
    2250368121 created

    您好!我查看了数据库数据是存在的,但是应用上没有加载出来

  • User Avatar
    0
    2250368121 created

    namespace QRSPC.AdministrationService;

    [DependsOn( typeof(AbpAuditLoggingEntityFrameworkCoreModule), typeof(TextTemplateManagementEntityFrameworkCoreModule), typeof(SaasEntityFrameworkCoreModule), typeof(BlobStoringDatabaseEntityFrameworkCoreModule), typeof(AbpPermissionManagementEntityFrameworkCoreModule), typeof(AbpFeatureManagementEntityFrameworkCoreModule), typeof(AbpSettingManagementEntityFrameworkCoreModule), typeof(LanguageManagementEntityFrameworkCoreModule), typeof(AbpEntityFrameworkCoreMySQLPomeloModule), typeof(AbpOpenIddictProDomainSharedModule), typeof(TextTemplateManagementApplicationModule), typeof(TextTemplateManagementHttpApiModule), typeof(LeptonXThemeManagementApplicationModule), typeof(LeptonXThemeManagementHttpApiModule), typeof(AbpAspNetCoreMvcUiMultiTenancyModule), typeof(QRSPCAdministrationServiceContractsModule), typeof(AbpPermissionManagementApplicationModule), typeof(AbpPermissionManagementHttpApiModule), typeof(AbpPermissionManagementDomainIdentityModule), typeof(AbpPermissionManagementDomainOpenIddictModule), typeof(AbpFeatureManagementApplicationModule), typeof(AbpFeatureManagementHttpApiModule), typeof(AbpSettingManagementApplicationModule), typeof(AbpSettingManagementHttpApiModule), typeof(AbpAutofacModule), typeof(AbpAspNetCoreSerilogModule), typeof(AbpSwashbuckleModule), typeof(AbpEventBusRabbitMqModule), typeof(AbpBackgroundJobsRabbitMqModule), typeof(AbpCachingStackExchangeRedisModule), typeof(AbpDistributedLockingModule), typeof(AbpAspNetCoreAuthenticationJwtBearerModule), typeof(AbpIdentityHttpApiClientModule), typeof(AbpStudioClientAspNetCoreModule) )] 这是administraiton 的依赖模块 是否要加上LanguageManagementDomainModule的引用?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    你好

    请先确认几个问题:

    1. 这个本地化问题是随机出现吗? 也就是刷新可能成功, 可能失败
    2. 切换到英文后. 刷新页面是否也会随机出现这个问题?
    3. 可以分享项目源码来复现问题吗?

    谢谢

  • User Avatar
    0
    2250368121 created

    编译重启后大概率就会出现语言加载问题 这是 baseSet源码 地址Deleted 感谢您!

  • User Avatar
    0
    2250368121 created

    过了个把小时就会正常

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    你的缓存服务器是否正常工作?

    这些信息都会存储到缓存中.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    你的这个页面是MVC还是Angular?

  • User Avatar
    0
    2250368121 created

    redis 工作正常

  • User Avatar
    0
    2250368121 created

    [Maliming] said: 你的这个页面是MVC还是Angular?

    是Angular 的

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    这大概率是缓存数据存在问题.

    Angular 从这个端点获取本地化信息

    https://your-web-gateway/api/abp/application-localization?cultureName=zh-Hans&onlyDynamics=false

    你可以访问试试.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    你可以在Administration中重写这个应用服务输出一些日志来看看哪里存在问题

    https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationLocalizationAppService.cs#L52

    输出所有的resources等信息到日志中.

    1. LocalizationOptions.Resources.Values
    2. await ExternalLocalizationStore.GetResourcesAsync()
    3. localizedStringsWithDynamics

    谢谢

  • User Avatar
    0
    2250368121 created

    好的 我先试试 谢谢您

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    没问题, 你可以随时反馈

  • User Avatar
    0
    2250368121 created

    "QRSPC.BaseSetService.Localization.BaseSetServiceResource": { "texts": { "Permission:Books": "Books", "Permission:BaseSetService": "基础设置", "Permission:Create": "创建", "Permission:Edit": "编辑", "Permission:Delete": "删除", "Books": "Books", "NewBook": "New Book", "Book": "Book", "Menu:Books": "Books", "SeeAdvancedFilters": "Filters", "DeleteConfirmationMessage": "Are you sure you want to delete this record?", "AreYouSure": "Are you sure?", "Search": "Search", "Pick": "Pick", "Actions": "Actions", "SuccessfullyDeleted": "Successfully deleted", "ExportToExcel": "导出Excel", "AllItemsAreSelected": "所有'{0}'项都被选中.", "OneItemOnThisPageIsSelected": "1 item on this page is selected", "NumberOfItemsOnThisPageAreSelected": "All {0} items on this page are selected", "SelectAllItems": "选择所有项", "ClearSelection": "清除选择", "DeleteAllRecords": "Are you sure you want to delete all records?", "DeleteSelectedRecords": "Are you sure you want to delete {0} record(s)?", "UploadFailedMessage": "Upload Failed: Unsupported file format or file size too large. Please ensure the file meets the required format and size limits, and try again.", "DownloadSelectedFile": "Download selected file", "RemoveSelectedFile": "Remove selected file", "Filters": "过滤", "BName": "B Name", "BCode": "B Code", "BMemo": "B Memo", "MinBName": "Min B Name", "MinBCode": "Min B Code", "MinBMemo": "Min B Memo", "MaxBName": "Max B Name", "MaxBCode": "Max B Code", "MaxBMemo": "Max B Memo", "BookDetails": "Book Details", "NewBookDetail": "New Book Detail", "BookDetail": "Book Detail", "Menu:BookDetails": "Book Details", "BDetailName": "B Detail Name", "BDetailCode": "B Detail Code", "MinBDetailName": "Min B Detail Name", "MinBDetailCode": "Min B Detail Code", "MaxBDetailName": "Max B Detail Name", "MaxBDetailCode": "Max B Detail Code", "Permission:BookDetails": "Book Details", "Permission:WorkStationSettings": "工位", "WorkStationSettings": "工位", "NewWorkStationSetting": "新建工位", "WorkStationSetting": "工位", "Menu:WorkStationSettings": "工位", "WorkStationSettingBaseCode": "工位编号", "WorkStationSettingBaseName": "工位名称", "BaseSetService": "基础设置" }, "baseResources": [ "AbpValidation", "AbpUi" ] }, 这是basesetservice中文资源包加载失败时https://spc-msa-sit.sungrow.cn/api/abp/application-localization?cultureName=zh-Hans&onlyDynamics=false 接口返回的bastsetService的资源数据与解决方案中的不一致 是redis的问题吗

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    可能是, 还是要输出一些日志看看那个服务返回了错误的数据

    参考: https://abp.io/support/questions/10180#answer-3a1e0f79-0c4a-f2ff-5121-227101208275

Learn More, Pay Less
33% OFF
All Trainings!
Get Your Deal
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.1.0-preview. Updated on December 25, 2025, 06:16
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.