在本文中,您将会了解到关于springpropertysubstitutionfortestandproduction的新资讯,并给出一些关于A.PrimeSubtraction(Educationa
在本文中,您将会了解到关于spring property substitution for test and production的新资讯,并给出一些关于A. Prime Subtraction ( Educational Codeforces Round 74 (Rated for Div. 2) )、BeanUtils.copyProperties(productInfo, productInfoVO);、Caused by: groovy.lang.MissingPropertyException: No such property: ID for class、Caused by: javax.el.PropertyNotFoundException: Property ''product'' not found on type java....的实用技巧。
本文目录一览:- spring property substitution for test and production
- A. Prime Subtraction ( Educational Codeforces Round 74 (Rated for Div. 2) )
- BeanUtils.copyProperties(productInfo, productInfoVO);
- Caused by: groovy.lang.MissingPropertyException: No such property: ID for class
- Caused by: javax.el.PropertyNotFoundException: Property ''product'' not found on type java....
spring property substitution for test and production
我在spring遇到这个问题
<context:property-placeholder location="esb-project-config.properties"/>
但是不幸的是,我们不想在xml文件中使用它,因为我们想在测试中重新使用该文件,但要交换test.properties文件进行测试。即。我们要测试所有生产绑定,但是要使用适合于测试的属性,例如localhost。如何加载具有不同属性文件的ApplicationContext?
答案1
小编典典将property-placeholder配置放入额外的spring xml配置文件中。
例如:
applicationContext.xml
-用于没有任何属性占位符配置的常规配置applicationContext-config.xml
-仅包含加载生产配置文件的属性占位符。testApplicationContext.xml
。该文件include为,applicationContext.xml并与其他属性文件一起使用属性占位符。
在Web App中,你可以使用此模式加载所有生产Spring上下文文件applicationContext*.xml
。
对于测试,你仅需要加载,testApplicationContext.xml
它将包括常规配置,但具有其他属性。
答案2
小编典典几种方法:
1.“Order”属性
在 src/main/resources/your-conf.xml
<context:property-placeholder location="classpath:esb-project-config.properties" order="1"/>
在 src/test/resources/your-test-config.xml
<context:property-placeholder location="classpath:esb-project-config.properties" order="0"/>
如果你运行测试src/test/resources
作为测试类路径,上面将确保覆盖src/main/resources/esb-project-config.properties用src/test/resources/esb-project-config.properties
。
property-placeholder
但是,这将覆盖整个实例,因此你必须在此测试中提供应用程序所需的所有属性property-placeholder。例如
<context:property-placeholder location="classpath:esb-project-config.properties, classpath:some-other-props-if-needed.properties" order="0"/>
- PropertyOverrideConfigurer
<context:property-override location="classpath:esb-project-config.test.properties"/>
覆盖某些单独的属性。这里的一些例子
3.系统变量
你可以使用前缀来控制特定于环境的属性,这可以通过使用系统变量来完成:
<context:property-placeholder location="${ENV_SYSTEM:dev}/esb-project-config.properties"/>
在这种情况下,它将始终处于以下状态:
<context:property-placeholder location="dev/esb-project-config.properties"/>
默认情况下,除非ENV_SYSTEM
设置了系统变量。qa
例如,如果将其设置为,它将自动在以下位置查找:
<context:property-placeholder location="qa/esb-project-config.properties"/>
4.spring概况
另一种方法是使bean配置文件特定。例如:
<beans profile="dev"> <context:property-placeholder location="esb-project-config.dev.properties"/></beans><beans profile="qa"> <context:property-placeholder location="esb-project-config.qa.properties"/></beans>
esb-project-config
将根据配置文件集加载适当的文件。例如,这将加载esb-project-config.dev.properties
:
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();ctx.getEnvironment().setActiveProfiles( "dev" );ctx.load( "classpath:/org/boom/bang/config/xml/*-config.xml" );ctx.refresh();
- 注意:“系统变量”和“系统配置文件”方法通常用于在不同的环境之间切换,而不仅仅是在开发人员模式下进行“开发<==>测试”,但是仍然需要注意有用的功能。
A. Prime Subtraction ( Educational Codeforces Round 74 (Rated for Div. 2) )
You are given two integers xx and yy (it is guaranteed that x>yx>y). You may choose any prime integer pp and subtract it any number of times from xx. Is it possible to make xx equal to yy?
Recall that a prime number is a positive integer that has exactly two positive divisors: 11 and this integer itself. The sequence of prime numbers starts with 22, 33, 55, 77, 1111.
Your program should solve tt independent test cases.
The first line contains one integer tt (1≤t≤10001≤t≤1000) — the number of test cases.
Then tt lines follow, each describing a test case. Each line contains two integers xx and yy (1≤y<x≤10181≤y<x≤1018).
For each test case, print YES if it is possible to choose a prime number pp and subtract it any number of times from xx so that xx becomes equal to yy. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).
4
100 98
42 32
1000000000000000000 1
41 40
YES
YES
YES
NO
In the first test of the example you may choose p=2p=2 and subtract it once.
In the second test of the example you may choose p=5p=5 and subtract it twice. Note that you cannot choose p=7p=7, subtract it, then choose p=3p=3 and subtract it again.
In the third test of the example you may choose p=3p=3 and subtract it 333333333333333333333333333333333333 times.
特判 0,1。
因为任何一个数都可以由 2 或者 2+1 组成,所以直接判断就行
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>n>>m;
if(n==m || n==m+1) cout<<"NO"<<endl;
else if((n-m)%2==0 ||(n-m)%3==0||(n-m)%5==0||(n-m)%7==0 )
cout<<"YES"<<endl;
}
}
BeanUtils.copyProperties(productInfo, productInfoVO);
一:spring 的工具类方法:BeanUtils.copyProperties (orderMasterDTO, orderMasterDO);
作用:将 orderMasterDTO 对象中的属性值,赋值到 orderMasterDO 中,其主要目的是利用反射机制对 JavaBean 的属性进行拷贝。
/**
* Copy the property values of the given source bean into the target bean.
* <p>Note: The source and target classes do not have to match or even be derived
* from each other, as long as the properties match. Any bean properties that the
* source bean exposes but the target bean does not will silently be ignored.
* <p>This is just a convenience method. For more complex transfer needs,
* consider using a full BeanWrapper.
* @param source the source bean
* @param target the target bean
* @throws BeansException if the copying failed
* @see BeanWrapper
*/
public static void copyProperties(Object source, Object target) throws BeansException {
copyProperties(source, target, null, (String[]) null);
}
二:好处:
不使 BeanUtils.copyProperties (orderMasterDTO, orderMasterDO) 方法的话,传统的做法是:手动将 orderMasterDTO 的属性值 set 到 orderMasterDO 中
OrderMasterDO orderMasterDO = new OrderMasterDO();
orderMasterDO.setOrderId(orderMasterDTO.getOrderId());
orderMasterDO.setBuyerName(orderMasterDTO.getBuyerName());
orderMasterDO.setOrderStatus(orderMasterDTO.getOrderStatus());
orderMasterDO.setCreateTimestamp(orderMasterDTO.getCreateTimestamp());
orderMasterDO.setUpdateTimestamp(orderMasterDTO.getUpdateTimestamp());
而使用了 BeanUtils 的工具方法,只需 BeanUtils.copyProperties (orderMasterDTO, orderMasterDO) 就可以 ojbk,简单方便多了。
注意:要注意该方法使用的地方,不然很有可能出现属性值丢失的问题
Caused by: groovy.lang.MissingPropertyException: No such property: ID for class
1、错误描述
Compiling to file... D:\Program Files (x86)\workspaces\report4.jasper Compilation running time: 3,096! Filling report... Locale: 中文 (中国) Time zone: Default Error filling print... Error evaluating expression : Source text : ID net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : Source text : ID at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:263) at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:611) at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:579) at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:1016) at net.sf.jasperreports.engine.fill.JRFillTextField.evaluateText(JRFillTextField.java:504) at net.sf.jasperreports.engine.fill.JRFillTextField.evaluate(JRFillTextField.java:488) at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:259) at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:456) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillBandNoOverflow(JRVerticalFiller.java:467) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnHeader(JRVerticalFiller.java:512) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:294) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:152) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:963) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:873) at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:87) at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:287) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:760) at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:891) at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572) at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997) Caused by: groovy.lang.MissingPropertyException: No such property: ID for class: report4_1445910598157_686313 at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50) at org.codehaus.groovy.runtime.callsite.GetEffectivePogopropertySite.getProperty(GetEffectivePogopropertySite.java:86) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231) at report4_1445910598157_686313.evaluate(calculator_report4_1445910598157_686313:180) at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:250) ... 19 more Print not filled. Try to use an EmptyDataSource...
2、错误原因
从错误提示可知,显示是没有ID这个属性,导致错误
3、解决办法
修改这个设置,保证每个字段都存在,描述都正确
Caused by: javax.el.PropertyNotFoundException: Property ''product'' not found on type java....
今天在JSP利用EL表达式取值报了 "javax.el.PropertyNotFoundException”,经过debug和打印将问题定位到这段代码:
HTML应该是没啥问题,看提示在java.lang.string类型上找不到属性“product”,应该是EL表达式哪里写错了,然后将图中EL表达式重新写了一遍:
然后神奇的不报错了,搞得我一脸蒙蔽,我将每段代码都比对了一下,没发现哪里不对,干就干彻底,替换每段代码测试,结果第一段替换进去就OK了
仔细检查了两段代码:
//报错代码
<c:forEach items="${order.orderItems } " var="orderItem">
//成功代码
<c:forEach items="${order.orderItems }" var="orderItem">
睁开我的钛合狗眼看了N遍,终于发现明明一样的代码,长度却不同。
再检查,细心又帅气的我发现第一段代码在EL表达式的花括号“}”结尾与双引号中间多了个空格
这里是不能有空格的
这玩意浪费我两小时的时间去排查,写代码的时候一定要细心细心再细心!
今天的关于spring property substitution for test and production的分享已经结束,谢谢您的关注,如果想了解更多关于A. Prime Subtraction ( Educational Codeforces Round 74 (Rated for Div. 2) )、BeanUtils.copyProperties(productInfo, productInfoVO);、Caused by: groovy.lang.MissingPropertyException: No such property: ID for class、Caused by: javax.el.PropertyNotFoundException: Property ''product'' not found on type java....的相关知识,请在本站进行查询。
本文标签: