此处将为大家介绍关于Modelmapper:当源对象为null时,如何应用自定义映射?的详细内容,并且为您解答有关源对象属性在哪里的相关问题,此外,我们还将为您介绍关于c#–AutoMapper–如何
此处将为大家介绍关于Modelmapper:当源对象为null时,如何应用自定义映射?的详细内容,并且为您解答有关源对象属性在哪里的相关问题,此外,我们还将为您介绍关于c# – AutoMapper – 如何映射到嵌套类型中的值 – 可能为null?、c# – Dapper.NET多映射TSecond Deserializer为null、c# – 使用自定义SqlMapper.ITypeHandler – Dapper将枚举映射到字符串列、c# – 如何在代码外定义AutoMapper映射,即在XML文件中定义或使用不同的方法进行完全可配置的对象映射?的有用信息。
本文目录一览:- Modelmapper:当源对象为null时,如何应用自定义映射?(源对象属性在哪里)
- c# – AutoMapper – 如何映射到嵌套类型中的值 – 可能为null?
- c# – Dapper.NET多映射TSecond Deserializer为null
- c# – 使用自定义SqlMapper.ITypeHandler – Dapper将枚举映射到字符串列
- c# – 如何在代码外定义AutoMapper映射,即在XML文件中定义或使用不同的方法进行完全可配置的对象映射?
Modelmapper:当源对象为null时,如何应用自定义映射?(源对象属性在哪里)
假设我有课MySource
:
public class MySource { public String fieldA; public String fieldB; public MySource(String A, String B) { this.fieldA = A; this.fieldB = B; }}
我想将其翻译为object MyTarget
:
public class MyTarget { public String fieldA; public String fieldB;}
使用默认的ModelMapper设置,我可以通过以下方式实现:
ModelMapper modelMapper = new ModelMapper();MySource src = new MySource("A field", "B field");MyTarget trg = modelMapper.map(src, MyTarget.class); //success! fields are copied
但是,可能会发生该MySource
对象null
。在这种情况下,MyTarget还将是null
:
ModelMapper modelMapper = new ModelMapper(); MySource src = null; MyTarget trg = modelMapper.map(src, MyTarget.class); //trg = null
我想以这种方式指定自定义映射,(伪代码):
MySource src != null ? [perform default mapping] : [return new MyTarget()]
有人知道如何编写适当的转换器来实现这一目标吗?
答案1
小编典典无法直接使用ModelMapper,因为ModelMappermap(Source, Destination)
方法会检查source是否为null,在这种情况下,它将引发异常。
看一下ModelMapper Map方法的实现:
public <D> D map(Object source, Class<D> destinationType) { Assert.notNull(source, "source"); -> //IllegalArgument Exception Assert.notNull(destinationType, "destinationType"); return mapInternal(source, null, destinationType, null); }
解
我建议扩展ModelMapper类并map(Object source, Class<D> destinationType)
像这样重写:
public class MyCustomizedMapper extends ModelMapper{ @Override public <D> D map(Object source, Class<D> destinationType) { Object tmpSource = source; if(source == null){ tmpSource = new Object(); } return super.map(tmpSource, destinationType); }}
它检查source是否为null,在这种情况下,它将初始化然后调用super map(Object source, Class<D>destinationType)
。
最后,您可以像这样使用自定义的映射器:
public static void main(String args[]){ //Your customized mapper ModelMapper modelMapper = new MyCustomizedMapper(); MySource src = null; MyTarget trg = modelMapper.map(src, MyTarget.class); //trg = null System.out.println(trg);}
输出将是new MyTarget()
:
输出控制台:NullExampleMain.MyTarget(fieldA = null,fieldB = null)
这样就被初始化了。
c# – AutoMapper – 如何映射到嵌套类型中的值 – 可能为null?
无论如何,我有一个像这样的域对象:
public class User { public string Name { get; set; } public FacebookUser FacebookUser { get; set; } }
像这样的viewmodel:
public class Userviewmodel { public string Name { get; set; } public long FacebookUniqueId { get; set; } }
这是我在AutoMapper配置中的内容:
Mapper.CreateMap<User,Userviewmodel>() .ForMember(dest => dest.FacebookUniqueId,opt => opt.MapFrom(src => src.FacebookUser.FacebookUniqueId))
但是当FacebookUser对象为null时,它会引发异常,这是预期的.
我如何告诉AutoMapper:
Map Userviewmodel.FacebookUniqueId to User.FacebookUser.FacebookUniqueId,except for when it’s null,then use
0
.
有任何想法吗?
解决方法
opt => opt.MapFrom(src => src.FacebookUser == null ? 0 : src.FacebookUser.FacebookUniqueId)
如果我刚刚检查过第一个想法是否有效,那就认为MapFrom方法只采用了一个指向属性的表达式来解决它…
c# – Dapper.NET多映射TSecond Deserializer为null
这是查询代码:
const string storedProc = "dbo.GetStopsForRouteID"; var stops = conn.Query<RouteStop,MapLocation,RouteStop>( storedProc,(stop,loc) => { stop.Location = loc; return stop; },new { RouteID = routeId },commandType: CommandType.StoredProcedure);
在第498行的Dapper.cs中:
var deserializer2 = (Func<IDataReader,TSecond>)info.OtherDeserializers[0];
info.OtherDeserializers为null,导致NullReferenceException.
这是存储过程的内容:
SELECT RouteStops.StopID,RouteStops.Name,RouteStops.Description,RouteStops.IsInbound,RouteStops.Location.Lat as Latitude,RouteStops.Location.Long as Longitude FROM dbo.Routes INNER JOIN dbo.StopsOnRoute ON Routes.RouteID = StopsOnRoute.RouteID INNER JOIN dbo.RouteStops ON StopsOnRoute.StopID = RouteStops.StopID WHERE Routes.RouteID = @RouteID ORDER BY StopsOnRoute.SequenceNumber
我已经对dapper代码进行了广泛的研究,但除了TFirst的deserialiser不是null之外我找不到任何看似不合适的东西,但是TSecond是.当它创建TSecond的反序列化器并将其保留为null时会出现问题吗?
以下是类型:
public class MapLocation { public double Latitude { get; set; } public double Longitude { get; set; } } public class RouteStop { public int StopID { get; set; } public string Name { get; set; } public string Description { get; set; } public bool IsInbound { get; set; } public MapLocation Location { get; set; } }
解决方法
splitOn: "Latitude"
没有它,只要dapper可以看到没有第二个结果部分(默认情况下它在Id上分裂).
c# – 使用自定义SqlMapper.ITypeHandler – Dapper将枚举映射到字符串列
如果我使用enum Foo {A,P}之类的单个字符名称的枚举,我很确定Dapper会正确映射它们但我不希望这样,我想要带有描述性标签的枚举如下:
enum Foo { [StringValue("A")] Active,[StringValue("P")] Proposed }
在上面的例子中,StringValueAttribute是一个自定义属性,我可以使用反射将“A”转换为Foo.Active,这很好 – 除了我需要Dapper为我执行转换逻辑.我写了一个自定义类型处理程序来执行此操作
public class EnumTypeHandler<T> : sqlMapper.TypeHandler<T> { public override T Parse(object value) { if (value == null || value is dbnull) { return default(T); } return EnumHelper.FromStringValue<T>(value.ToString()); } public override void SetValue(IDbDataParameter parameter,T value) { parameter.DbType = DbType.String; parameter.Value = EnumHelper.GetStringValue(value as Enum); } } //Usage: sqlMapper.AddTypeHandler(typeof(Foo),(sqlMapper.ITypeHandler)Activator.CreateInstance(typeof(EnumTypeHandler<>).MakeGenericType(typeof(Foo)));
使用sqlMapper.AddTypeHandler()注册似乎工作正常,但是当我的DbConnection.Query()代码运行时,我收到一条错误,指出无法转换值’A’ – 从Enum.Parse抛出错误,提示Dapper实际上并没有调用我的类型处理程序,尽管它已被注册.有没有人知道这方面的方法?
解决方法
c# – 如何在代码外定义AutoMapper映射,即在XML文件中定义或使用不同的方法进行完全可配置的对象映射?
从AutoMapper wiki我学会了创建一个简单的映射
Mapper.CreateMap<CalendarEvent,CalendarEventForm>().ForMember(dest => dest.Title,opt => opt.MapFrom(src => src.Title)); Mapper.CreateMap<CalendarEvent,CalendarEventForm>().ForMember(dest => dest.EventDate,opt => opt.MapFrom(src => src.EventDate.Date)); Mapper.CreateMap<CalendarEvent,CalendarEventForm>().ForMember(dest => dest.EventHour,opt => opt.MapFrom(src => src.EventDate.Hour)); Mapper.CreateMap<CalendarEvent,CalendarEventForm>().ForMember(dest => dest.EventMinute,opt => opt.MapFrom(src => src.EventDate.Minute));
像两个班
public class CalendarEvent { public DateTime EventDate; public string Title; } public class CalendarEventForm { public DateTime EventDate { get; set; } public int EventHour { get; set; } public int EventMinute { get; set; } public string Title { get; set; } }
我现在想知道是否有可能在外部定义映射,例如在XML文件中
<ObjectMapping> <mapping> <src>Title</src> <dest>Tile</dest> </mapping> <mapping> <src>EventDate.Date</src> <dest>EventDate</dest> </mapping> <mapping> <src>EventDate.Hour</src> <dest>EventHour</dest> </mapping> <mapping> <src>EventDate.Minute</src> <dest>EventMinute</dest> </mapping>
并通过这种影响创建地图(XML不是一个要求,也可以是其他一切).
为简单起见,说类型没有问题,所以src和dest应该是相同的,否则可以失败.这背后的想法是在应该映射的内容和应该映射的位置上非常灵活.我正在考虑根据其名称获取属性值的反射,但这似乎不起作用.
我也不确定这是否有意义,或者我是否遗漏了重要的东西,所以我们非常感谢帮助和想法.
解决方法
我使用了here和here中的代码,并添加了类PropertyMapping来存储从XML读取的映射,还添加类Foo和Bar来创建嵌套数据结构,以便复制到.
无论如何这里是代码,也许它可以帮助某人一些时间:
主要:
public class Program { public static void Main(string[] args) { // Model var calendarEvent = new CalendarEvent { EventDate = new DateTime(2008,12,15,20,30,0),Title = "Company Holiday Party" }; MyObjectMapper mTut = new MyObjectMapper(@"SampleMappings.xml"); Console.WriteLine(string.Format("Result MyMapper: {0}",Program.CompareObjects(calendarEvent,mTut.TestMyObjectMapperProjection(calendarEvent)))); Console.ReadLine(); } public static bool CompareObjects(CalendarEvent calendarEvent,CalendarEventForm form) { return calendarEvent.EventDate.Date.Equals(form.EventDate) && calendarEvent.EventDate.Hour.Equals(form.EventHour) && calendarEvent.EventDate.Minute.Equals(form.EventMinute) && calendarEvent.Title.Equals(form.Title); } }
Mapper实现:
public class MyObjectMapper { private List<PropertyMapping> myMappings = new List<PropertyMapping>(); public MyObjectMapper(string xmlFile) { this.myMappings = GenerateMappingObjectsFromXml(xmlFile); } /* * Actual mapping; iterate over internal mappings and copy each source value to destination value (types have to be the same) */ public CalendarEventForm TestMyObjectMapperProjection(CalendarEvent calendarEvent) { CalendarEventForm calendarEventForm = new CalendarEventForm(); foreach (PropertyMapping propertyMapping in myMappings) { object originalValue = GetPropValue(calendarEvent,propertyMapping.FromPropertyName); SetPropValue(propertyMapping.ToPropertyName,calendarEventForm,originalValue); } return calendarEventForm; } /* * Get the property value from the source object */ private object GetPropValue(object obj,String compoundProperty) { foreach (String part in compoundProperty.Split('.')) { if (obj == null) { return null; } Type type = obj.GetType(); PropertyInfo info = type.GetProperty(part); if (info == null) { return null; } obj = info.GetValue(obj,null); } return obj; } /* * Set property in the destination object,create new empty objects if needed in case of nested structure */ public void SetPropValue(string compoundProperty,object target,object value) { string[] bits = compoundProperty.Split('.'); for (int i = 0; i < bits.Length - 1; i++) { PropertyInfo propertyToGet = target.GetType().GetProperty(bits[i]); propertyToGet.SetValue(target,Activator.CreateInstance(propertyToGet.PropertyType)); target = propertyToGet.GetValue(target,null); } PropertyInfo propertyToSet = target.GetType().GetProperty(bits.Last()); propertyToSet.SetValue(target,value,null); } /* * Read XML file from the provided file path an create internal mapping objects */ private List<PropertyMapping> GenerateMappingObjectsFromXml(string xmlFile) { XElement definedMappings = XElement.Load(xmlFile); List<PropertyMapping> mappings = new List<PropertyMapping>(); foreach (XElement singleMappingElement in definedMappings.Elements("mapping")) { mappings.Add(new PropertyMapping(singleMappingElement.Element("src").Value,singleMappingElement.Element("dest").Value)); } return mappings; } }
我的模型类:
public class CalendarEvent { public DateTime EventDate { get; set; } public string Title { get; set; } } public class CalendarEventForm { public DateTime EventDate { get; set; } public int EventHour { get; set; } public int EventMinute { get; set; } public string Title { get; set; } public Foo Foo { get; set; } } public class Foo { public Bar Bar { get; set; } } public class Bar { public DateTime InternalDate { get; set; } }
内部映射表示:
public class PropertyMapping { public string FromPropertyName; public string ToPropertyName; public PropertyMapping(string fromPropertyName,string toPropertyName) { this.FromPropertyName = fromPropertyName; this.ToPropertyName = toPropertyName; } }
示例XML配置:
<?xml version="1.0" encoding="utf-8" ?> <ObjectMapping> <mapping> <src>Title</src> <dest>Title</dest> </mapping> <mapping> <src>EventDate.Date</src> <dest>EventDate</dest> </mapping> <mapping> <src>EventDate.Hour</src> <dest>EventHour</dest> </mapping> <mapping> <src>EventDate.Minute</src> <dest>EventMinute</dest> </mapping> <mapping> <src>EventDate</src> <dest>Foo.Bar.InternalDate</dest> </mapping> </ObjectMapping>
关于Modelmapper:当源对象为null时,如何应用自定义映射?和源对象属性在哪里的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于c# – AutoMapper – 如何映射到嵌套类型中的值 – 可能为null?、c# – Dapper.NET多映射TSecond Deserializer为null、c# – 使用自定义SqlMapper.ITypeHandler – Dapper将枚举映射到字符串列、c# – 如何在代码外定义AutoMapper映射,即在XML文件中定义或使用不同的方法进行完全可配置的对象映射?等相关知识的信息别忘了在本站进行查找喔。
以上就是给各位分享如何选择Maven-gpg-plugin用于对工件进行签名的GnuPG密钥?,其中也会对maven gpg plugin进行解释,同时本文还将给你拓展centos6 – rpm在哪里安装自定义gpg密钥?、Failed to execute goal maven-gpg-plugin 1.5 Sign、gnupg – gpg2中的gpg-agent、gnupg – gpg物理保护私钥文件等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:- 如何选择Maven-gpg-plugin用于对工件进行签名的GnuPG密钥?(maven gpg plugin)
- centos6 – rpm在哪里安装自定义gpg密钥?
- Failed to execute goal maven-gpg-plugin 1.5 Sign
- gnupg – gpg2中的gpg-agent
- gnupg – gpg物理保护私钥文件
如何选择Maven-gpg-plugin用于对工件进行签名的GnuPG密钥?(maven gpg plugin)
我正在使用maven-gpg-
plugin对Maven工件进行签名。这可以正常工作,但是我的GnuPG密钥环中有多个密钥,并且希望使用与GnuPG选择的密钥不同的密钥。
如果有多个密钥,GnuPG如何选择“默认”密钥?
是否可以指定要在maven-gpg-plugin配置中使用的密钥?似乎
keyname
不起作用(我假设它选择了钥匙圈,但没有选择特定的钥匙)。
答案1
小编典典如果有多个键,GPG如何选择“默认”键?
如果没有其他定义(例如,使用default-key
选项),则GnuPG默认情况下会选择秘密密钥环中的第一个密钥。来自man gpg
:
--default-key name Use name as the default key to sign with. If this option is not used, the default key is the first key found in the secret keyring. Note that -u or --local-user overrides this option.
是否可以指定要在maven-gpg-plugin配置中使用的密钥?似乎“密钥名”不起作用(我假设它选择了密钥环,但没有选择特定的密钥)。
如果您不想让GnuPG自动决定要使用哪个密钥,请<keyname>[keyname]</keyname>
选择要使用的密钥。我希望这是作为local-key
选项传递的,因此它应该支持短键和长键ID,指纹和用户ID。GnuPG手册包含指定密钥的方法列表。
大多数在此描述如何指定密钥的手册都使用短密钥ID,由于碰撞攻击,我强烈建议不要这样做,而应使用整个指纹。
还有其他选项可以更改键的选择。有关各个选项的更多详细信息,请参阅Maven
GnuPG插件手册:
- 使用选择专用的钥匙圈
secretKeyring
- 使用以下命令选择专用的GnuPG主目录
homedir
local-user
使用以下选项将选项传递给GnuPGgpgArguments
centos6 – rpm在哪里安装自定义gpg密钥?
wget http://Nginx.org/keys/Nginx_signing.key rpm --import Nginx_signing.key [root@web1-ftl rpm-gpg]# rpm -qi gpg-pubkey-7bd9bf62-4e4e3262 Name : gpg-pubkey Relocations: (not relocatable) Version : 7bd9bf62 vendor: (none) Release : 4e4e3262 Build Date: Wed 05 Feb 2014 03:26:35 AM UTC Install Date: Wed 05 Feb 2014 03:26:35 AM UTC Build Host: localhost Group : Public Keys Source RPM: (none) Size : 0 License: pubkey Signature : (none) Summary : gpg(Nginx signing key <signing-key@Nginx.com>) Description : -----BEGIN PGP PUBLIC KEY BLOCK----- Version: rpm-4.8.0 (NSS-3) mQENBE5OMmIBCAD+FPYKGriGGf7NqwKfWC83cBV01gabgVWQmZbMcFzeW+hMsgxH W6iimD0RsfZ9oEbfJCPG0CRSZ7ppq5pKamYs2+EJ8Q2ysOFHHwpGrA2C8zyNAs4I QxnZZIbETgcSwFtDun0XiqPwPZgyuXVm9PAbLZRbfBzm8wR/3SWygqZBBLdQk5TE fdr+Eny/M1RVR4xClECONF9UBB2ejFdI1LD45APbP2hsN/piFByU1t7yK2gpFyRt 97WzGHn9MV5/TL7AmRPM4pcr3JacmtCnxXeCZ8nLqedoSuHFuhwyDnlAbu8I16O5 XRrfzhrHRJFM1JnIiGmzZi6zBvH0ItfyX6ttABEBAAG0KW5naW54IHNpZ25pbmcg a2V5IDxzaWduaW5nLWtleUBuZ2lueC5jb20+iQE+BBMBAgAoBQJOTjJiAhsDBQkJ ZgGABgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRCr9b2Ce9m/YpvjB/98uV4t 94d0oEh5XlqEZzVMrcTgPQ3BZt05N5xVuYaglv7OQtdlErMXmRWaFZEqdamHdniC sF63jWMd29vC4xpzIfmsLK3ce9oYo4t9o4WWqBUdf0Ff1LMz1dfLG2HDtKPfYg3C 8nesud09zuP5NohaE8Qzj/4p6rWDiRpuZ++4fnL3Dt3N6jXILwr/TM/Ma7jvaXGP DO3kzm4dNKp5b5bn2nT2QWLPnEKxvOg5Zoej8l9+KFsUnXoWoYCkMQ2QTpZQFNwF xwJGoAz8K3PwVPUrIL6b1lsiNovDgcgP0eDgzvwLynWKBPkRRjtgmWLoeaS9FAZV ccXJMmANXJFuCf26iQEcBBABAgAGBQJOTkelAAoJEKZP1bF62zmo79oH/1XDb29S YtWp+MTJTPFEwlWRiyRuDXy3wBd/BpwBRIWfWzMs1gnCjNjk0EVBVGa2grvy9Jtx JKMd6l/PWXVucSt+U/+GO8rBkw14SdhqxaS2l14v6gyMeUrSbY3XfToGfwHC4sa/ Thn8X4jFaQ2XN5dAIzJGU1s5JA0tjEzUwCnmrKmyMlXZaoQVrmORGjCuH0I0aAFk RS0UtnB9HppxhGVbs24xXZQnZDNbUQeulFxS4uP3OLDBAeCHl+v4t/uotIad8v6J SO93vc1evIje6lguE81HHmJn9noxPItvOvSMb2yPsE8mH4cJHRTFNSEhPW6ghmlf Wa9ZwiVX5igxcvaIRgQQEQIABgUCTk5b0gAKCRDs8OkLLBcgg1G+AKCnacLb/+W6 cflirUIExgZdUJqoogCeNPVwXiHEIVqithAM1pdY/gcaQZmIRgQQEQIABgUCTk5f YQAKCRCpN2E5pSTFPnNWAJ9gUozyiS+9jf2rJvqmJSeWuCgVRwCcCUFhXRCpQO2Y Va3l3WuB+rgKjsQ= =A015 -----END PGP PUBLIC KEY BLOCK-----
Digital signatures cannot be verified without a public key. An ASCII armored public key can be added to the rpm database using --import. An imported public key is carried in a header,and keyring management is performed exactly like package management. For example,all currently imported public keys can be displayed by: rpm -qa gpg-pubkey* Details about a specific public key,when imported,can be displayed by querying. Here’s information about the Red Hat GPG/DSA key: rpm -qi gpg-pubkey-db42a60e Finally,public keys can be erased after importing just like packages. Here’s how to remove the Red Hat GPG/DSA key rpm -e gpg-pubkey-db42a60e
/ etc / pki / rpm-gpg是具有存储库配置(如epel-release)的软件包的标准位置,用于放置要导入的密钥.包中的yum配置将具有gpgkey指令中键的路径.第一次尝试从存储库安装软件包时,yum会提示您导入密钥.
Failed to execute goal maven-gpg-plugin 1.5 Sign
问题描述:
解决办法:跳过maven-gpg-plugin
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
如果是父子工程,检父工程里面是否引入了这个插件,如果有直接注释即可
gnupg – gpg2中的gpg-agent
gpg --batch --no-tty --no-use-agent --symmetric --cipher-algo AES256 --passphrase "foobar" /path/to/file_to_be_encrypted
如果没有–no-use-agent选项,我会收到臭名昭着的错误消息
gpg-agent is not available in this session
我担心转移到gpg2因为,according to the documentation,gpg-agent总是需要的,而且–no-use-agent只是一个虚拟选项.我的gpg调用通过守护进程在后台发生,所以这是一个非代理方案(加上它是对称的,我根本不需要代理).
这个详细程度的文档很少,所以我正在寻找用户体验. gpg2是否更紧密地合并了代理,因此我不必担心它的可用性?
解决方法
gpg2 --batch --yes --no-tty --no-use-agent --symmetric --cipher-algo AES256 --passphrase "foobar" /path/to/file_to_be_encrypted
>当你使用对称加密时(就像你一样),密码短语约束(即使设置为由gpg-agent强制执行)也不会被应用 – 它只会起作用.
假设gpg-agent是这样运行的(让mypasswords文件甚至包含与您的密码完全匹配的禁用模式):
eval $(gpg-agent --daemon --enforce-passphrase-constraints --min-passphrase-len 8 --min-passphrase-nonalpha 4 --check-passphrase-pattern mypasswords)
然后你的命令仍然会成功.
简而言之:gpg-agent不会让它失败(除非因某些原因崩溃gpg – 如错误配置或丢失可执行文件,你无法解释).
编辑:我刚检查并在对称模式下gpg2将工作,即使gpg-agent配置错误或gpg-agent可执行文件丢失.
这是不相关的,但以防万一:我还验证了当你试图在gpg-agent缺失或配置错误时更改私钥密码时会发生什么:gpg2会报告一个警告,甚至不会要求新的密码,并继续工作.
资料来源:
> gpg-agent
configuration manual
> gpg
documentation
gnupg – gpg物理保护私钥文件
drwx------ 2 jason jason 4096 Feb 11 21:10 ./ drwx------ 90 jason jason 45056 Feb 11 20:49 ../ -rw------- 1 jason jason 9398 Feb 11 20:49 gpg.conf -rw-rw-r-- 1 jason jason 2316 Feb 11 21:10 mypk -rw------- 1 jason jason 1633 Feb 11 20:52 pubring.gpg -rw------- 1 jason jason 1633 Feb 11 20:52 pubring.gpg~ -rw------- 1 jason jason 600 Feb 11 20:52 random_seed -rw------- 1 jason jason 1794 Feb 11 20:52 secring.gpg -rw------- 1 jason jason 1280 Feb 11 20:52 trustdb.gpg
我是否正确理解secring.gpg是我的私钥?这个文件受我的密码保护,对吧?将此文件保存在我的机器上可以吗?我应该把它移到更安全的地方(比如拇指驱动器)吗?
解决方法
Am I correct to understand that secring.gpg is my private key?
来自男人gpg:
~/.gnupg/secring.gpg The secret keyring. You should backup this file.
This file is protected by my passphrase,right?
如果你设置一个,是的.实际上文件本身并不受保护,但每个包含的密钥都可以(您的密钥环中可以有多个私钥).
Is it ok to just keep this file on my machine? Should I move it somewhere more secure (say a thumb drive)?
这取决于您的需求和对机器的信任.
>您是否有特殊的安全需求,共享您的机器或期望它被黑/被盗/ ……?最好把它放在外部设备上,然后每当使用gpg时将其引用–secret-keyring /path/to/secring.gpg或将其放入你的gpg.conf:secret-keyring /path/to/secring.gpg.
>您是否相信计算机的完整性,甚至可能加密了您的文件?你需要经常使用你的密钥吗?最好将文件保存在硬盘上,因为这样可以省去使用gpg的麻烦.
要将密钥放在单独的设备上,请考虑使用OpenPGP card.使用一个,您的密钥永远不会离开该卡(用于签名和解密),而是用于备份目的.绝对也会增加书呆子因素.
总结
以上是小编为你收集整理的gnupg – gpg物理保护私钥文件全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
我们今天的关于如何选择Maven-gpg-plugin用于对工件进行签名的GnuPG密钥?和maven gpg plugin的分享已经告一段落,感谢您的关注,如果您想了解更多关于centos6 – rpm在哪里安装自定义gpg密钥?、Failed to execute goal maven-gpg-plugin 1.5 Sign、gnupg – gpg2中的gpg-agent、gnupg – gpg物理保护私钥文件的相关信息,请在本站查询。
想了解Android棉花糖中的SimpleDateFormat行为更改的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于棉花糖app怎么不能用了的相关问题,此外,我们还将为您介绍关于android SimpleDateFormat(“dd / mm / yyyy”)效果不佳、Android SimpleDateFormat,如何使用?、Android studio 使用SimpleDateFormat格式化时间格式,导致程序闪退、android – SimpleDateFormat子类在这一年增加了1900的新知识。
本文目录一览:- Android棉花糖中的SimpleDateFormat行为更改(棉花糖app怎么不能用了)
- android SimpleDateFormat(“dd / mm / yyyy”)效果不佳
- Android SimpleDateFormat,如何使用?
- Android studio 使用SimpleDateFormat格式化时间格式,导致程序闪退
- android – SimpleDateFormat子类在这一年增加了1900
Android棉花糖中的SimpleDateFormat行为更改(棉花糖app怎么不能用了)
我在Android
6.0(棉花糖)上遇到了日期格式问题。引发以下异常的代码是我的应用程序用于API请求(“客户端”)的纯Java库(单独构建)。如果相关的话,该库是用Java
1.6构建的……无论如何,这是代码。
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd E hh:mm aa", Locale.UK);Date eventDate = dateFormat.parse(StringUtils.substring(record, 0, 23).trim());
… record
具有价值;
2015-10-23 Fri 10:59 PM BST 3.60 meters
…“修剪”之后是;
2015-10-23 Fri 10:59 PMyyyy-MM-dd E hh:mm aa
该代码自Froyo成立以来一直有效,并且已经过单元测试。除了棉花糖,所有东西都会抛出异常。
10-23 21:01:56.816 4091-4110/com.oceanlife E/ParseException: SynchroniseTidePosition.doInBackground10-23 21:01:56.816 4091-4110/com.oceanlife E/ParseException: java.text.ParseException: Unparseable date: "2015-10-23 Fri 10:59 PM" (at offset 21)10-23 21:01:56.816 4091-4110/com.oceanlife E/ParseException: at java.text.DateFormat.parse(DateFormat.java:579)10-23 21:01:56.816 4091-4110/com.oceanlife E/ParseException: at com.oceanlife.rover.handler.XTideParser.parseResponse(XTideParser.java:69)10-23 21:01:56.816 4091-4110/com.oceanlife E/ParseException: at com.brantapps.oceanlife.task.SynchroniseTidePosition.doInBackground(SynchroniseTidePosition.java:107)10-23 21:01:56.816 4091-4110/com.oceanlife E/ParseException: at com.brantapps.oceanlife.task.SynchroniseTidePosition.doInBackground(SynchroniseTidePosition.java:43)10-23 21:01:56.816 4091-4110/com.oceanlife E/ParseException: at android.os.AsyncTask$2.call(AsyncTask.java:295)10-23 21:01:56.816 4091-4110/com.oceanlife E/ParseException: at java.util.concurrent.FutureTask.run(FutureTask.java:237)10-23 21:01:56.816 4091-4110/com.oceanlife E/ParseException: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)10-23 21:01:56.816 4091-4110/com.oceanlife E/ParseException: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)10-23 21:01:56.816 4091-4110/com.oceanlife E/ParseException: at java.lang.Thread.run(Thread.java:818)
偏移量“ 21”是10:59中“ 9”之后的空格。谁能解释这个失败?
更新资料
切换到joda-time,它会显示更多信息的错误消息。这里是;
Invalid format ... is malformed at "PM"
…所以,这是关于要解析的字符串的AM / PM方面-
回到文档
答案1
小编典典在英国语言环境中,“ am”和“ pm”的定义似乎已更改。
在棉花糖中,英国区域设置现在将“ am”表示为“ am”,将“ pm”表示为“ pm”
String record = "2015-10-23 Fri 10:59 p.m. BST 3.60 meters"SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd E hh:mm aa", Locale.UK);// note the length is 25 now, not 23... Date eventDate = dateFormat.parse(StringUtils.substring(record, 0, 25).trim());
我无法解释为什么,但是美国语言环境与am / pm合作,英国与am / pm合作
编辑
似乎在2015年3月的en_gb
语言环境更新中,该语言环境已替换其am /
pm定义。源差异
android SimpleDateFormat(“dd / mm / yyyy”)效果不佳
private void setDateInTopBar() { Date bodyPartDate = DataManager.instance().getSelectedBodyPart().getPublicationDate(); SimpleDateFormat format = new SimpleDateFormat("dd/mm/yyyy"); String formattedDate = format.format(bodyPartDate); TextView dateTxt = (TextView) findViewById(R.id.txtimageDate); dateTxt.setText(formattedDate); }
但我的月份是0,当日和年工作正常时,问题是什么?
解决方法
SimpleDateFormat format = new SimpleDateFormat("dd/mm/yyyy");
附:
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
因为毫米参考分钟..检查http://developer.android.com/reference/java/text/SimpleDateFormat.html
Android SimpleDateFormat,如何使用?
我试图SimpleDateFormat
像这样使用Android :
String _Date = "2010-09-29 08:45:22"
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
try {
Date date = fmt.parse(_Date);
return fmt.format(date);
}
catch(ParseException pe) {
return "Date";
}
结果很好,我有:2010-09-29
但是如果我更改SimpleDateFormat
为
SimpleDateFormat("dd-MM-yyyy");
问题是我会得到03-03-0035 !!!!
为什么以及如何获取格式dd-MM-yyyy
?
Android studio 使用SimpleDateFormat格式化时间格式,导致程序闪退
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateStr = sdf.format(date);
应用闪退,有如下错误
java.lang.NoClassDefFoundError: android.icu.text.SimpleDateFormat
应用运行闪退是因为 这个方法在Android studio 中最低SDK版本24,
因为导入的包
import android.icu.text.SimpleDateFormat;
这个包在SDK 24版本之后才出现的
把这个包替换成Java原有的
import java.text.SimpleDateFormat;
即可解决
android – SimpleDateFormat子类在这一年增加了1900
public class ISO8601TLDateFormat extends SimpleDateFormat { private static String mISO8601T = "yyyy-MM-dd''T''HH:mm:ss.SSSZ"; public ISO8601TLDateFormat() { super(mISO8601T); } public ISO8601TLDateFormat(Locale inLocale) { super(mISO8601T,inLocale); } }
正如您所看到的,目的是生成或解释日期
2012-03-17T00:00:00.000 0100
这是Azure服务所期望的.但是,当我输入从DatePicker构造的Date对象时:
mDate = new Date(mDatePicker.getYear(),mDatePicker.getMonth(),mDatePicker.getDayOfMonth());
ISO8601TLDateFormat的输出是
3912-03-17T00:00:00.000 0100
正如你所看到的,这一年比我更多,或者不是未来的任何人都需要.我已经仔细检查了Date对象到Azure Feed系统的整个过程,它报告的日期是2012年,这是我所期望的.为什么SimpleDateFormat会破坏?
解决方法
public Date(int year,int month,int date) Deprecated. As of JDK version 1.1,replaced by Calendar.set(year + 1900,month,date) or GregorianCalendar(year + 1900,date). Allocates a Date object and initializes it so that it represents midnight,local time,at the beginning of the day specified by the year,and date arguments. Parameters: year - the year minus 1900. month - the month between 0-11. date - the day of the month between 1-31.
你需要记住,你构造的日期是0,1,是1900年1月1日.
我们今天的关于Android棉花糖中的SimpleDateFormat行为更改和棉花糖app怎么不能用了的分享就到这里,谢谢您的阅读,如果想了解更多关于android SimpleDateFormat(“dd / mm / yyyy”)效果不佳、Android SimpleDateFormat,如何使用?、Android studio 使用SimpleDateFormat格式化时间格式,导致程序闪退、android – SimpleDateFormat子类在这一年增加了1900的相关信息,可以在本站进行搜索。
以上就是给各位分享weblogic.xml中的错误:cvc-complex-type.2.4.a:发现无效的内容,其中也会对从元素“ prefer-application- packages”开始进行解释,同时本文还将给你拓展.net – 消耗webservice的错误,内容类型“application/xop xml”与预期类型不匹配“text/xml”、android – 如何将applicationJacksonHttpMessageConverter的内容类型从application / json; charset = UTF-8更改为appl、application.properties 在 maven-compiler-plugin 期间更改、applicationId和packageName,以及在Manifest中使用${applicationId}写法等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:- weblogic.xml中的错误:cvc-complex-type.2.4.a:发现无效的内容(从元素“ prefer-application- packages”开始)
- .net – 消耗webservice的错误,内容类型“application/xop xml”与预期类型不匹配“text/xml”
- android – 如何将applicationJacksonHttpMessageConverter的内容类型从application / json; charset = UTF-8更改为appl
- application.properties 在 maven-compiler-plugin 期间更改
- applicationId和packageName,以及在Manifest中使用${applicationId}写法
weblogic.xml中的错误:cvc-complex-type.2.4.a:发现无效的内容(从元素“ prefer-application- packages”开始)
我正在使用springs源工具套件。我在weblogic.xml文件中遇到错误-
cvc-complex-type.2.4.a: Invalid content was found starting with element ''prefer- application-packages''. One of ''{"http://www.bea.com/ns/weblogic/weblogic-web-app":retain-original-url, "http://www.bea.com/ns/weblogic/weblogic-web-app":show-archived-real-path-enabled, "http://www.bea.com/ns/weblogic/weblogic-web-app":require-admin-traffic, "http://www.bea.com/ns/weblogic/weblogic-web-app":access-logging-disabled}'' is expected.enter code here
我的weblogic.xml看起来像这样
<?xml version="1.0"?><weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd"><jsp-descriptor> <keepgenerated>true</keepgenerated> <page-check-seconds>60</page-check-seconds> <precompile>true</precompile> <precompile-continue>true</precompile-continue></jsp-descriptor><container-descriptor> <optimistic-serialization>true</optimistic-serialization> <prefer-application-packages> <package-name>antlr.*</package-name> <package-name>javax.persistence.*</package-name> <package-name>org.apache.commons.*</package-name> </prefer-application-packages> <show-archived-real-path-enabled>true</show-archived-real-path-enabled></container-descriptor></weblogic-web-app>
错误显示在标签的开头。
答案1
小编典典weblogic-web-appxmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsdhttp://xmlns.oracle.com/weblogic/weblogic-web-apphttp://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
将名称空间更改为上述名称空间。
.net – 消耗webservice的错误,内容类型“application/xop xml”与预期类型不匹配“text/xml”
每当我尝试调用webservice上的任何方法时,调用实际上会成功,但是当处理响应时客户端失败,并且我收到异常。
错误的细节如下,谢谢你们可以提供的任何帮助。
使用Web引用错误(旧式webservice客户端)
当作为Web引用使用该服务时,我得到一个InvalidOperationException用于我所做的任何调用,并显示以下消息:
Client found response content type of ''multipart/related; type="application/xop+xml"; boundary="uuid:170e63fa-183c-4b18-9364-c62ca545a6e0"; start="<root.message@cxf.apache.org>"; start-info="text/xml"'',but expected ''text/xml''. The request Failed with the error message: -- --uuid:170e63fa-183c-4b18-9364-c62ca545a6e0 Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"; Content-transfer-encoding: binary Content-ID: <root.message@cxf.apache.org> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <ns2:openApiConnectionResponse xmlns:ns2="http://api.service.apibatchmember.emailvision.com/" xmlns:ns3="http://exceptions.service.apibatchmember.emailvision.com/"> <return>DpKTe-9swUeOsxhHH9t-uLPeLyg-aa2xk3-aKe9oJ5S9Yymrnuf1FxYnzpaFojsQSkSCbJsZmrZ_d3v2-7Hj</return> </ns2:openApiConnectionResponse> </soap:Body> </soap:Envelope> --uuid:170e63fa-183c-4b18-9364-c62ca545a6e0-- --.
如你所见,响应肥皂包看起来是有效的(这是一个有效的响应,并且调用成功),但客户端似乎对内容类型有问题并产生异常。
使用服务引用错误(WCF客户端)
当我将服务作为服务参考使用时,我会收到一个ProtocolException用于我所做的任何调用,并显示以下消息:
The content type multipart/related; type="application/xop+xml"; boundary="uuid:af66440a-012e-4444-8814-895c843de5ec"; start="<root.message@cxf.apache.org>"; start-info="text/xml" of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder,be sure that the IsContentTypeSupported method is implemented properly. The first 648 bytes of the response were: '' --uuid:af66440a-012e-4444-8814-895c843de5ec Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"; Content-transfer-encoding: binary Content-ID: <root.message@cxf.apache.org> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <ns2:openApiConnectionResponse xmlns:ns2="http://api.service.apibatchmember.emailvision.com/" xmlns:ns3="http://exceptions.service.apibatchmember.emailvision.com/"> <return>Dqaqb-MJ9V_eplZ8fPh4tdHUbxM-ZtuZsDG6galAGZSfSzyxgtuuIxZc3aSsnhI4b0SCbJsZmrZ_d3v2-7G8</return> </ns2:openApiConnectionResponse> </soap:Body> </soap:Envelope> --uuid:af66440a-012e-4444-8814-895c843de5ec--''.
就像前面的例子一样;我们有一个有效的soap响应,并且调用成功,但客户端似乎对内容类型有问题,并产生了异常。
有没有我可以设置的选项,所以客户端没有响应类型的问题?我已经做了一些谷歌的搜索,但我发现没有什么帮助我到目前为止。
解决方法
以下是所需配置设置的代码段:
<configuration> <system.serviceModel> <bindings> <basicHttpBinding> <binding messageEncoding="Mtom"> </binding> </basicHttpBinding> </bindings> </system.serviceModel> </configuration>
编辑:如果您有与自定义绑定相同的问题,请参阅answer from @robmzd。
我仍然没有找到一个解决方案来消费它作为一个旧式的Web引用。
android – 如何将applicationJacksonHttpMessageConverter的内容类型从application / json; charset = UTF-8更改为appl
我有一个Spring REST Web服务,在我的控制器中,我使用MappingJacksonHttpMessageConverter将我的返回模型转换为JSON.但是当我用firebug检查它时,有Content-Type = application / json; charset = UTF-8.
此外,我试图通过使用spring android rest模板从Android客户端解析此结果但我不断得到:
Could not extract response: no
suitable HttpMessageConverter found
for response type
[xxx.SamplePageActivity$Result] and
content type
application/json;charset=UTF-8]
可能是android客户端上的MappingJacksonHttpMessageConverter完全期望类型application / json的情况
所以我的问题是如何改变spring的MappingJacksonHttpMessageConverter从application / json返回Content-Type; charset = UTF-8到application / json.
这是我的视图解析器配置.这可能很有用:
<beans:bean>
<beans:property name="mediaTypes">
<beans:map>
<beans:entry key="html" value="text/html" />
<beans:entry key="json" value="application/json" />
</beans:map>
</beans:property>
<beans:property name="viewResolvers">
<beans:list>
<beans:bean>
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value="${dispatcher.suffix}" />
</beans:bean>
</beans:list>
</beans:property>
<beans:property name="defaultviews">
<beans:list>
<beans:beanhttps://www.jb51.cc/tag/njs/" target="_blank">njsonView" />
</beans:list>
</beans:property>
</beans:bean>
<beans:bean id="messageAdapter">
<beans:property name="messageConverters">
<beans:list>
<!-- Support JSON -->
<beans:bean/>
</beans:list>
</beans:property>
</beans:bean>
解决方法:
您可以使用supportedMediaTypes属性更精确地配置MappingJacksonHttpMessageConverter,如下所示:
<bean>
<property name="supportedMediaTypes">
<list>
<bean>
<constructor-arg value="application" />
<constructor-arg value="json" />
<constructor-arg value="#{T(java.nio.charset.Charset).forName('UTF-8')}"/>
</bean>
</list>
</property>
</bean>
根据文档(http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/http/MediaType.html),您可以按顺序设置类型,子类型和字符集 –
application.properties 在 maven-compiler-plugin 期间更改
如何解决application.properties 在 maven-compiler-plugin 期间更改?
Github 存储库
https://github.com/rennyong/demo
Maven 命令
mvn clean package -Pprod -Dmaven.test.skip=true
异常行为
如果您在 maven 命令运行时离开 target/classes/resources/application.properties,您将看到以下异常行为: 已删除 >> spring.profiles.active=prod spring.profiles.active=@spring.profiles.active@
预期结果/结果
应仅过滤以下属性!
spring.profiles.active=prod
POM.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<!-- File Download-->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<!--metamodel Generator
Auto generation of Meta model for specifications-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.4.29.Final</version>
<scope>provided</scope>
</dependency>
<!--Mapping Dto-->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.4.2.Final</version>
</dependency>
<!--
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
<scope>provided</scope>
</dependency> -->
<!-- Auto Generation of getter/setter and constructor-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.18</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>show-profiles</id>
<phase>compile</phase>
<goals>
<goal>active-profiles</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
<!-- This is needed when using Lombok 1.18.16 and above -->
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.4.2.Final</version>
</path>
<path>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.4.29.Final</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>prod</id>
<properties>
<spring.profiles.active>prod</spring.profiles.active>
</properties>
</profile>
<profile>
<id>dev</id>
<properties>
<spring.profiles.active>dev</spring.profiles.active>
</properties>
</profile>
</profiles>
</project>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
applicationId和packageName,以及在Manifest中使用${applicationId}写法
1. 前言
- 本文资料来源网络公开资源,并根据个人实践见解纯手打整理,如有错误请随时指出。
- 本文主要用于个人积累及分享,文中可能引用其他技术大牛文章(仅引用链接不转载),如有侵权请告知必妥善处理。
2. applicationId
和packageName
2.1. IDE
为Eclipse
时
applicationId
基于gradle编译,Eclipse IDE
不存在applicationId
,也不能使用它,请忽略。
2.2. IDE
为Android Studio
时
2.2.1 applicationId
- 理论上来讲
applicationId
是android
设备以及google play
所公认的唯一标示。 - 若未配置
applicationId
时,google play
无法上线(据查) - 配置
applicationId
可以用作同一工程发布略有差异的不同apk
,比如收费版和免费版、代码相同标示不同的渠道包等。 -
配置方法(在
app
的build.gradle
中):-
一般配置
android { ...... defaultConfig { applicationId "sp.com.learncomposite" ...... } }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 1
- 2
- 3
- 4
- 5
- 6
- 7
-
设置不同的
applicationId
配置
其中关于productFlavors
的应用可以参考这篇文章很详细:链接,或者参考官方文档:链接1,链接2。android { ...... productFlavors { pro { applicationId = "sp.com.learncomposite.pro" } free { applicationId = "sp.com.learncomposite.free" } } buildTypes { ...... debug { applicationIdSuffix ".debug" } } }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
-
-
当
release
打包时,在签名界面,可以选择你将要打出的包,也可以多选并同时打出:
-
当
debug
调试时,可以再Android studio
左下角的Build Variants
标签中选择当前调试的是哪个包:
2.2.2 packageName
- 将仅被代码(如资源文件
R.java
)或Manifest
清单中声明(如类的包路径和packageName
相同时,activity
的name
缩写为”.xxxActivity
“)使用。
2.2.3 两者纠缠的关系
- 当
applicationId
不存在时,applicationId
将默认为packageName
。 - 当
applicationId
存在时,packageName
仅有其本身的功能,而applicationId
将作为唯一标示。
3. 在Manifest
中使用${applicationId}
-
如
Provider
在声明android:authorities
(该值必须唯一)时,如前缀为写死的包名字符串,当出现需要同一工程分包、分渠道打包时,安装在同一android
设备将导致INSTALL FAILED CONFLICTING PROVIDER
的报错(使用adb
安装会有提示),这时可以使用${applicationId}
,这将避免android:authorities
值非唯一的问题。<provider android:name="xxxx.xxxx.xxx.xxxProvider" android:authorities="${applicationId}.xxxx" android:grantUriPermissions="true" android:exported="false"/>
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
-
${applicationId}
也可以用在Manifest
中其他需要唯一的取值情况,这种使用方式很灵活。
我们今天的关于weblogic.xml中的错误:cvc-complex-type.2.4.a:发现无效的内容和从元素“ prefer-application- packages”开始的分享已经告一段落,感谢您的关注,如果您想了解更多关于.net – 消耗webservice的错误,内容类型“application/xop xml”与预期类型不匹配“text/xml”、android – 如何将applicationJacksonHttpMessageConverter的内容类型从application / json; charset = UTF-8更改为appl、application.properties 在 maven-compiler-plugin 期间更改、applicationId和packageName,以及在Manifest中使用${applicationId}写法的相关信息,请在本站查询。
本文标签: