学习ABP遇到的问题汇总
1,在abp官网下载的模板(asp.net+ef)写Application层的时候需要使用AutoMapper。结果ObjectMapper一直为null
解决:需要在当前项目的Module依赖AbpAutoMapperModule
2,Linq Include扩展方法需要引用EntityFramework.dll
3,ToListAsync扩展方法需要引用using Abp.Linq.Extensions;
4,手动搭建abp2.x老是出现System.Collections.Immutable1.2.1.0找不到
解决:
①编辑项目web.config改为(这个可以不管)
- <dependentAssembly>
- <assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-1.2.1.0" newVersion="1.2.1.0" />
- </dependentAssembly>
②编辑项目工程文件(例如Demo.Web.csproj文件)
案例下载:http://pan.baidu.com/s/1kU7By31
5,创建租户(独立数据库)报MSDTC 不可用
解决方案:
打开windows服务开启Distributed Transaction Coordinator服务
6,单元测试时老是报个错:
解决:
单元测试Module需要依赖AbpTestBaseModule
7,运行模板项目报错
解决办法:删除项目下的bin目录,然后重新编译就好了
8, 把Abp.Zero.Common添加到项目报错
解决方法:
在Abp.Zero.Common.csproj文件中删除
9,本地化失效
解决方法:需要把xml设置为嵌入的资源
10,更改提示变成中文
扩展本地化文件
在Ousutec.Duty.Core中的DutyLocalizationConfigurer的Configure方法加上扩展配置
- using Abp.Configuration.Startup;
- using Abp.Localization.Dictionaries;
- using Abp.Localization.Dictionaries.Xml;
- using Abp.Localization.Sources;
- using Abp.Reflection.Extensions;
- namespace Ousutec.Duty.Localization
- {
- public static class DutyLocalizationConfigurer
- {
- public static void Configure(ILocalizationConfiguration localizationConfiguration)
- {
- localizationConfiguration.Sources.Add(
- new DictionaryBasedLocalizationSource(DutyConsts.LocalizationSourceName,
- new XmlEmbeddedFileLocalizationDictionaryProvider(
- typeof(DutyLocalizationConfigurer).GetAssembly(),
- "Ousutec.Duty.Localization.SourceFiles"
- )
- )
- );
- localizationConfiguration.Sources.Extensions.Add(
- new LocalizationSourceExtensionInfo("AbpWeb",
- new XmlEmbeddedFileLocalizationDictionaryProvider(
- typeof(DutyLocalizationConfigurer).GetAssembly(),
- "Ousutec.Duty.Localization.AbpWebExtensions"
- )
- )
- );
- }
- }
- }
DutyLocalizationConfigurer
将Abp.Web.Common源码的AbpWeb-zh-Hans.xml复制到Ousutec.Duty.Core项目中。并嵌入资源
11,关于自动注册依赖
约定名称必须一直,例如
- using System;
- using System.Collections.Generic;
- using System.Text;
- using Castle.Core.Logging;
- using Ousutec.Duty.Common;
- using Newtonsoft.Json;
- using Abp.Dependency;
- using Ousutec.Duty.DutyCmds;
- using Abp.AutoMapper;
- namespace Ousutec.Duty.RabbitMqListeners
- {
- public class DutyCmdListener : IDutyCmdListener, ITransientDependency
- {
- private readonly ILogger _logger;
- private readonly IDutyCmdAppService _dutyCmdAppService;
- public DutyCmdListener(ILogger logger, IDutyCmdAppService dutyCmdAppService)
- {
- _logger = logger;
- _dutyCmdAppService = dutyCmdAppService;
- }
- public void ProcessMsg(DutyCmdMessage msg)
- {
- _logger.Info(JsonConvert.SerializeObject(msg));
- _dutyCmdAppService.Add(msg.DutyCmdDtos.MapTo<IEnumerable<Addinput>>());
- }
- }
- }
DutyCmdListener
不一致会 报找不到依赖异常
12,Swagger CustomSchemaIds错误
Conflicting schemaIds: Identical schemaIds detected for types Ousutec.Duty.DutyRecords.AddInput and Ousutec.Duty.DutyDevSettings.AddInput. See config settings - "CustomSchemaIds" for a workaround
解决方法: options.CustomSchemaIds(t => t.FullName);
- // Swagger - Enable this line and the related lines in Configure method to enable swagger UI
- services.AddSwaggerGen(options =>
- {
- options.SwaggerDoc("v1", new Info { Title = "Duty API", Version = "v1" });
- options.DocInclusionPredicate((docName, description) => true);
- options.CustomSchemaIds(t => t.FullName);
- // Define the BearerAuth scheme that's in use
- options.AddSecurityDefinition("bearerAuth", new ApiKeyScheme()
- {
- Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
- Name = "Authorization",
- In = "header",
- Type = "apiKey"
- });
- // Assign scope requirements to operations based on AuthorizeAttribute
- options.OperationFilter<SecurityRequirementsOperationFilter>();
- });
Startup
13,接口返回参数命名,忽略abp框架设置的命名规则
- using System;
- using System.Linq;
- using System.Reflection;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Mvc.Cors.Internal;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- using Castle.Facilities.Logging;
- using Swashbuckle.AspNetCore.Swagger;
- using Abp.AspNetCore;
- using Abp.Castle.Logging.Log4Net;
- using Abp.Extensions;
- using Ousu.DataCollection.Attendance.Authentication.JwtBearer;
- using Ousu.DataCollection.Attendance.Configuration;
- using Ousu.DataCollection.Attendance.Identity;
- using Ousu.DataCollection.Attendance.Common;
- using Abp.AspNetCore.SignalR.Hubs;
- using Ousu.DataCollection.Attendance.AttendanceCmds;
- using Abp.Dependency;
- using Castle.Windsor.MsDependencyInjection;
- using Aliyun.OSS;
- using Castle.Core.Logging;
- using Abp.Json;
- using Newtonsoft.Json.Serialization;
- using Abp;
- namespace Ousu.DataCollection.Attendance.Web.Host.Startup
- {
- public class Startup
- {
- private const string _defaultCorsPolicyName = "localhost";
- private readonly IConfigurationRoot _appConfiguration;
- public Startup(IHostingEnvironment env)
- {
- _appConfiguration = env.GetAppConfiguration();
- }
- public IServiceProvider ConfigureServices(IServiceCollection services)
- {
- // MVC
- services.AddMvc(
- options =>
- {
- options.Filters.Add(new CorsAuthorizationFilterFactory(_defaultCorsPolicyName));
- }
- );
- IdentityRegistrar.Register(services);
- AuthConfigurer.Configure(services, _appConfiguration);
- services.AddSignalR();
- // Configure CORS for angular2 UI
- services.AddCors(
- options => options.AddPolicy(
- _defaultCorsPolicyName,
- builder => builder
- .WithOrigins(
- // App:CorsOrigins in appsettings.json can contain more than one address separated by comma.
- _appConfiguration["App:CorsOrigins"]
- .Split(",", StringSplitOptions.RemoveEmptyEntries)
- .Select(o => o.RemovePostFix("/"))
- .ToArray()
- )
- .AllowAnyHeader()
- .AllowAnyMethod()
- .AllowCredentials()
- )
- );
- // Swagger - Enable this line and the related lines in Configure method to enable swagger UI
- services.AddSwaggerGen(options =>
- {
- options.SwaggerDoc("v1", new Info { Title = "Attendance API", Version = "v1" });
- options.DocInclusionPredicate((docName, description) => true);
- options.CustomSchemaIds(t => t.FullName);
- // Define the BearerAuth scheme that's in use
- options.AddSecurityDefinition("bearerAuth", new ApiKeyScheme()
- {
- Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
- Name = "Authorization",
- In = "header",
- Type = "apiKey"
- });
- // Assign scope requirements to operations based on AuthorizeAttribute
- options.OperationFilter<SecurityRequirementsOperationFilter>();
- });
- //去除abp框架自带的命名规则
- services.PostConfigure<MvcJsonOptions>(options =>
- {
- options.SerializerSettings.ContractResolver = new AbpContractResolver();
- });
- // Configure Abp and Dependency Injection
- return services.AddAbp<AttendanceWebHostModule>(
- // Configure Log4Net logging
- options =>
- {
- options.IocManager.IocContainer.AddFacility<LoggingFacility>(f => f.UseAbpLog4Net().WithConfig("log4net.config"));
- }
- );
- }
- public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
- {
- app.UseAbp(options => { options.UseAbpRequestLocalization = false;}); // Initializes ABP framework.
- app.UseCors(_defaultCorsPolicyName); // Enable CORS!
- app.UseStaticFiles();
- app.UseAuthentication();
- app.UseAbpRequestLocalization();
- app.UseSignalR(routes =>
- {
- routes.MapHub<AbpCommonHub>("/signalr");
- });
- app.UseMvc(routes =>
- {
- routes.MapRoute(
- name: "defaultWithArea",
- template: "{area}/{controller=Home}/{action=Index}/{id?}");
- routes.MapRoute(
- name: "default",
- template: "{controller=Home}/{action=Index}/{id?}");
- });
- // Enable middleware to serve generated Swagger as a JSON endpoint
- app.UseSwagger();
- // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.)
- app.UseSwaggerUI(options =>
- {
- options.SwaggerEndpoint(_appConfiguration["App:ServerRootAddress"] + "/swagger/v1/swagger.json", "Attendance API V1");
- options.IndexStream = () => Assembly.GetExecutingAssembly()
- .GetManifestResourceStream("Ousu.DataCollection.Attendance.Web.Host.wwwroot.swagger.ui.index.html");
- }); // URL: /swagger
- }
- }
- }
去除abp框架自带的命名规则
14,不使用abp框架自带的返回格式
在类或者方法上加上[DontWrapResult]特性
学习ABP遇到的问题汇总的更多相关文章
- ABP入门系列(1)——学习Abp框架之实操演练
作为.Net工地搬砖长工一名,一直致力于挖坑(Bug)填坑(Debug),但技术却不见长进.也曾热情于新技术的学习,憧憬过成为技术大拿.从前端到后端,从bootstrap到javascript,从py ...
- 学习ABP ASP.NET Core with Angular 环境问题
1. 前言 最近学习ABP架构 搭建ASP.NET Core with Angular遇到了些问题,折腾了一个礼拜最终在今天解决了,想想这个过程的痛苦就想利用博客记录下来.其实一直想写博客,但因为 时 ...
- ABP入门系列目录——学习Abp框架之实操演练
ABP是"ASP.NET Boilerplate Project (ASP.NET样板项目)"的简称. ASP.NET Boilerplate是一个用最佳实践和流行技术开发现代WE ...
- 2019 年起如何开始学习 ABP 框架系列文章-开篇有益
2019 年起如何开始学习 ABP 框架系列文章-开篇有益 [[TOC]] 本系列文章推荐阅读地址为:52ABP 开发文档 https://www.52abp.com/Wiki/52abp/lates ...
- 学习abp vnext框架到精简到我的Vop框架
学习目标 框架特点 基于.NET 5平台开发 模块化系统 极少依赖 极易扩展 ....... 框架目的 学习.NET 5平台 学习abp vnext 上图大部分功能已经实现,多数是参考(copy)ab ...
- 关于OpenStack的学习路线及相关资源汇总
首先我们想学习openstack,那么openstack是什么?能干什么?涉及的初衷是什么?由什么来组成?刚接触openstack,说openstack不是一个软件,而是由多个组件进行组合,这是一个更 ...
- python学习两月总结_汇总大牛们的思想_值得收藏
下面是我汇总的我学习两个月python(version:3.3.2)的所有笔记 你可以访问:http://www.python.org获取更多信息 你也可以访问:http://www.cnblogs. ...
- django学习-15.ORM查询方法汇总
1.前言 django的ORM框架提供的查询数据库表数据的方法很多,不同的方法返回的结果也不太一样,不同方法都有各自对应的使用场景. 主要常用的查询方法个数是13个,按照特点分为这4类: 方法返回值是 ...
- 一步一步学习ABP项目系列文章目录
1.概述 基于DDD的.NET开发框架 - ABP初探 基于DDD的.NET开发框架 - ABP分层设计 基于DDD的.NET开发框架 - ABP模块设计 基于DDD的.NET开发框架 - ABP启动 ...
随机推荐
- OpenStack API部分高可用配置(二)
一.安装与配置HAProxy 1.调整内核参数,允许绑定VIP: vim /etc/sysctl.conf [内容] net.ipv4.ip_nonlocal_bind=1 sysctl -p 2.安 ...
- Kafka 0.8 宕机问题排查步骤
CPU 利用率高的排查方法 看看该机器的连接数是不是比其他机器多,监听的端口数:netstat -anlp | wc -l Kafka-0.8的停止和启动 启动: cd /usr/local/kafk ...
- hdu 527 Necklace
http://acm.hdu.edu.cn/showproblem.php?pid=5727 阶乘 爆搜阴性宝石的排列,二分图最大匹配判断最多能使多少个阳性宝石不褪色 注: 1.O(n-1 !) 即可 ...
- 阿里云(一)云存储OSS的命令行osscmd的安装和使用
一.安装Python 在Linux Shell里验证Python版本: $ python -V Python 2.7.10 二.安装OSScmd SDK osscmd是基于python 2.5.4(其 ...
- 用python处理文本,本地文件系统以及使用数据库的知识基础
主要是想通过python之流的脚本语言来进行文件系统的遍历,处理文本以及使用简易数据库的操作. 本文基于陈皓的:<程序员技术练级攻略> 一.Python csv 对于电子表格和数据库导出文 ...
- [python]使用python实现Hadoop MapReduce程序:计算一组数据的均值和方差
这是参照<机器学习实战>中第15章“大数据与MapReduce”的内容,因为作者写作时hadoop版本和现在的版本相差很大,所以在Hadoop上运行python写的MapReduce程序时 ...
- lemon spj无效编译器解决方法
反正我是被坑了很久,心里增的敲难过呀! 我曾经无数次的想把它解决掉: 啊啊啊啊啊啊! 什么嘛!什么嘛! 这个空白的框框里到底要填什么嘛!!! 你已经是一个成熟的lemon了,就不能自动识别给个选项吗! ...
- xml json
简单概括的话就是,xml本身是一种格式规范,是一种包含了数据以及数据说明的文本格式规范. 比如,我们要给对方传输一段数据,数据内容是“too young,too simple,sometimes na ...
- mybatis批量增加与删除——(十五)
1.首先应该明白,mybatis增删改返回值是int型的影响行数的值 mapper接口 package cn.xm.mapper; import java.util.List; import cn.x ...
- 基于theano的多层感知机的实现
1.引言 一个多层感知机(Multi-Layer Perceptron,MLP)可以看做是,在逻辑回归分类器的中间加了非线性转换的隐层,这种转换把数据映射到一个线性可分的空间.一个单隐层的MLP就可以 ...