我是使用IntelliJ Idea的新手,我有以下代码:
private boolean verifyToken(TokenTypeEnum expectedTokenType, Token token) {
return token != null &&
token.getTokenType() == expectedTokenType &&
token.getExpiryDate().isAfter(Instant.now());
}
Run Code Online (Sandbox Code Playgroud)
现在,IntelliJ-IDEA抱怨这个布尔方法总是被反转.但我特意写了这个方法,所以它返回一个正面,我不想让方法isInvalidToken或类似的东西.我认为这个警告的重点实际上是为了避免那些负面因素.
更重要的是,如果我实际让IntelliJ自动反转方法,它会使这样的表达式完全不是我想要的,因为它更难以推理(即使我会重写日期比较)
private boolean newNegativeMethod(TokenTypeEnum expectedTokenType, Token token) {
return token == null ||
token.getTokenType() != expectedTokenType ||
!token.getExpiryDate().isAfter(Instant.now());
}
Run Code Online (Sandbox Code Playgroud)
它为什么这样做?我当然可以禁用警告,但我不愿意.
在Spring Boot 2.1.0 EvaluationContextExtensionSupport中不推荐使用,https : //docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/repository/query/spi/EvaluationContextExtensionSupport.html 表示要实现EvaluationContextExtension直
即使它只是被弃用,它立即开始使用此堆栈跟踪进行此升级失败:
Caused by: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'methodSecurityInterceptor' defined in class path resource [org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.class]: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration; factoryMethodName=methodSecurityInterceptor; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.class]] for bean 'methodSecurityInterceptor': There is already [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=methodSecurityConfiguration; factoryMethodName=methodSecurityInterceptor; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [ournamespace/configuration/MethodSecurityConfiguration.class]] bound.
at …Run Code Online (Sandbox Code Playgroud) 我在Eclipse中记录代码,并且一直使用/**,然后输入很多来插入Javadoc模板.但是,由于某些原因,这并不总是有效,它将创建用于编写注释的模板,但它不会自动插入@param和@return文本.如果我将完全相同的方法复制到另一个类,它将插入完整的模板.
如果有人能告诉我为什么在某些情况下它不会这样做,那将是一个很大的帮助.
使用 Spring Security 5 oauth 我成功地使用 Google 作为 OAuth 提供程序完成了整个身份验证/授权周期,但是如果我使用我自己制作的 OAuth 提供程序运行在不同的应用程序上,我就会陷入困境。
我正在使用以下 2 个依赖项:
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-jose</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
使用谷歌,我刚刚配置了这个:
spring.security.oauth2.client.registration.google.client-id=xxx
spring.security.oauth2.client.registration.google.client-secret=xxx
Run Code Online (Sandbox Code Playgroud)
使用 Google(或 Facebook、Github 或 Okta)时,有一个默认配置负责其他设置。
现在我创建了自己的 OAuth 提供程序。这也是一个 Spring Boot 应用程序,配置了@EnableAuthorizationServer其他标准,但它具有自定义主体。这也在本地主机上运行,但端口为 8081。资源服务器中的配置如下:
spring.security.oauth2.client.registration.bx.client-id=xxx
spring.security.oauth2.client.registration.bx.client-secret=xxx
spring.security.oauth2.client.registration.bx.client-name=bx
spring.security.oauth2.client.registration.bx.provider=bx
spring.security.oauth2.client.registration.bx.scope=user
spring.security.oauth2.client.registration.bx.redirect-uri-template=http://localhost:8080/login/oauth2/code/bx
spring.security.oauth2.client.registration.bx.client-authentication-method=basic
spring.security.oauth2.client.registration.bx.authorization-grant-type=authorization_code
spring.security.oauth2.client.provider.bx.authorization-uri=http://localhost:8081/oauth/authorize
spring.security.oauth2.client.provider.bx.token-uri=http://localhost:8081/oauth/token
spring.security.oauth2.client.provider.bx.user-info-uri=http://localhost:8081/oauth/userInfo
spring.security.oauth2.client.provider.bx.user-name-attribute=name
Run Code Online (Sandbox Code Playgroud)
当尝试使用它登录时,我被正确重定向到 OAuth 提供程序,在那里我可以登录并允许使用默认生成的界面访问请求的范围:
点击授权后,我卡在了回调部分。我可以看到回调
http://localhost:8080/login/oauth2/code/bx?code=xxx&state=xxx
从 oauth 服务器返回,这会导致 Spring 中的默认 HTML 页面显示以下信息:
您的登录尝试不成功,请重试。
原因:[authorization_request_not_found]
使用 OAuth 2.0 登录
谷歌
bx
资源服务器的日志比较长,但是我提取了有用的部分:
19:20:07.985 [http-nio-8080-exec-9] DEBUG o.a.coyote.http11.Http11InputBuffer - Received [GET …Run Code Online (Sandbox Code Playgroud) java spring-security oauth-2.0 spring-boot spring-security-oauth2
我正在使用XSLT样式表(由Antennahouse)将XHTML转换为XSL-FO文件.我在我的XHTML文件中将一个空行定义为2个连续的HTML BR标记.现在,XSL-FO格式的空白行没有原生支持.我想通过在样式表为BR标记插入的fo:block中添加一个高度来解决这个限制.但是,我是XSLT语言的新手,我在这方面遇到了一些问题.
我可以弄清楚如何为我遇到的每个BR标签插入这个高度,但我只想在彼此之后有2个BR标签时插入空白行(否则在每个文本后面都会插入一个空行,然后是BR标签.)
我得到了一个"无意义"的表达式(11大于10),它将定义何时插入常规的fo:block或fo:block with space-after ="1em".显然这个表达没有任何意义,它应该检查的是这个BR元素是否是连续的第二个元素.如果有人能帮助我或指出我正确的方向,我将不胜感激.这就是我现在所拥有的:
<xsl:template match="html:br">
<xsl:choose>
<xsl:when test="11 > 10">
<fo:block space-after="1em">
<xsl:call-template name="process-common-attributes"/>
</fo:block>
</xsl:when>
<xsl:otherwise>
<fo:block>
<xsl:call-template name="process-common-attributes"/>
</fo:block>
</xsl:otherwise>
</xsl:choose>
Run Code Online (Sandbox Code Playgroud)
为了便于参考,这是一个XHTML,我希望将双BR标签转换为空行,但单个BR标签应该只是一个常规换行符.
<div style="color: #000000; font-family: arial; font-size: 10pt; font-style: normal; font-weight: normal;">
<span>description</span>
<br/>
<span>using</span>
<br/>
<span>multiple</span>
<br/>
<span>lines</span>
<br/>
<br/>
<span>with</span>
<br/>
<br/>
<span>blank</span>
<br/>
<br/>
<span>lines</span>
<br/>
</div>
Run Code Online (Sandbox Code Playgroud) 在构建XSL文档时,我遇到了以下问题.我想在原始文本中保留换行符,所以我设置了linefeed-treatment="preserve".但是,这显然也意味着它保留了文本内容之外和实际xml元素中的换行符.一个例子:
String content = "<fo:block white-space-collapse=\"true\" ><fo:inline>this is some </fo:inline><fo:inline font-weight=\"bold\">custom</fo:inline><fo:inline> \ncontent</fo:inline></fo:block>";
Run Code Online (Sandbox Code Playgroud)
这是我用作输入的文本.它被转换为Java中的xml文档.请注意在指示新行的内容之前的\n.这将导致FO文档中的以下输出:
<fo:block white-space-collapse="true" linefeed-treatment="preserve">
<fo:inline>this is some</fo:inline>
<fo:inline font-weight="bold">custom</fo:inline>
<fo:inline>
content</fo:inline>
</fo:block>
Run Code Online (Sandbox Code Playgroud)
所以它确实在文本内容之前显示了换行符,这很好.
我使用Apache FOP将其转换为PDF文件以及另一个第三方库,将其转换为DocX文件.在这两种情况下,内容都将显示如下:
这是一些
习惯内容
当我手动更改我的XSL并使其像这样:
<fo:block white-space-collapse="true" linefeed-treatment="preserve"><fo:inline>this is some </fo:inline><fo:inline font-weight="bold">custom</fo:inline><fo:inline>
content</fo:inline></fo:block>
Run Code Online (Sandbox Code Playgroud)
然后我的输出很好,就像我期望的那样:
这是一些自定义
内容
显然,我不希望这些额外的换行符来自元素本身,但我确实希望保留文本内容中的换行符.有没有办法做到这一点?或者是否有其他解决方案可以对我的换行符进行排序?
我们有一个请求来实现我们的网络服务响应,以便 xsd:decimal 小数位数在模式指示时不够长时将被零填充。我想知道这是否是一个合理的请求,以及 xsd:decimal 是否应该与这些模式一起使用。根据他们的规范,这是 xsd 的相关部分:
<xsd:simpleType>
<xsd:restriction base="xsd:decimal">
<xsd:totalDigits value="14"/>
<xsd:fractionDigits value="2"/>
<xsd:pattern value="[\-+]?[0-9]{1,12}[.][0-9]{2}"/>
</xsd:restriction>
</xsd:simpleType>
Run Code Online (Sandbox Code Playgroud)
因此,fractionDigits 设置为 2,这意味着精度最多可以为 2 位。根据http://zvon.org/xxl/XMLSchemaTutorial/Output/ser_types_st2.html,如果小数位数较少(例如对于像 5.1 这样的数字),也可以
但是根据模式 {2} 应该总是有 2 个小数位。
我们正在开发一个通用的应用程序开发平台 (Mendix),并且无法提前知道小数将用于什么(货币、pH 值、距离等)。这个案例来自一个使用我们平台的特定项目,但通常我们不知道正在传输什么样的数据。我们可以决定在这方面只遵循 WSDL,其中规定它应该有 2 个小数位。但是我们对它的实现必须非常通用。
没有任何内容说明这些小数位数应该填充什么,甚至我们应该填充而不是完全省略这个小数。理论上我们可以决定用 5 填充直到它与模式匹配。据我所知,模式很少使用,如果是的话,它用于密码之类的东西。XSD 规范虽然含糊不清,因此如果有人能够阐明这是否是 XSD 的有效使用以及我们决定用 0 填充是否有意义,我们将不胜感激。
考虑这个代码:
import java.math.BigDecimal;
import java.math.RoundingMode;
public class RoundingTests {
public static void main(String[] args) {
BigDecimal bd1 = new BigDecimal(265.345d);
BigDecimal bd2 = new BigDecimal(265.335d);
System.out.println("Setting scale 265.345: " + bd1.setScale(2, RoundingMode.HALF_EVEN));
System.out.println("Setting scale 265.335: " + bd2.setScale(2, RoundingMode.HALF_EVEN));
}
}
Run Code Online (Sandbox Code Playgroud)
输出是:
Setting scale 265.345: 265.35
Setting scale 265.335: 265.33
Run Code Online (Sandbox Code Playgroud)
现在这与我的预期完全相反。随着RoundingMode.HALF_EVEN(也称为银行家四舍五入)我期待这两个值成为价值265.34
请注意,我不是BigDecimal.round故意使用该方法,因为它也不是我需要的。如果我添加此代码(并导入 java.math.MathContext):
System.out.println("Rounding 265.345: " + bd1.round(new MathContext(2, RoundingMode.HALF_EVEN)));
System.out.println("Rounding 265.335: " + bd2.round(new MathContext(2, RoundingMode.HALF_EVEN)));
Run Code Online (Sandbox Code Playgroud)
然后输出是:
Rounding 265.345: 2.7E+2
Rounding 265.335: 2.7E+2
Run Code Online (Sandbox Code Playgroud)
这是意料之中的,也在 …
使用Mendix Business Modeler构建Web应用程序与使用Java/Spring/JSF等技术开发Web应用程序有着根本的不同.但是,为了这个问题,我将尝试比较两者:
在基于Java/Spring的应用程序中,我可以将我的应用程序与第三方产品Ehcache集成,以在方法级别缓存数据.例如,我可以配置ehcache来存储给定方法的返回值(具有特定的生存时间).每当调用此方法时,ecache将自动检查先前是否使用相同的参数调用了方法,以及缓存中是否存在存储的返回值.如果是这样,则永远不会实际执行该方法,而是立即返回缓存的方法返回值.
我希望在Mendix中具有相同的功能,但在这种情况下,我将缓存Microflow返回值.此外,我不希望被强制在整个地方添加操作,明确告诉Microflow检查缓存.我想在一个集中的地方注册我的Microflows进行缓存,或者只是标记每个Microflow进行缓存.换句话说,这个问题与Mendix中面向方面编程(AOP)的概念一样多,因为它是关于缓存的:有没有一种方法可以挂钩进入Microflow调用,以便我可以应用前后执行操作?在我看来,同样的原因也就是为什么AOP在Java中有它的目的.
我需要能够编辑 Pageable 对象,更具体地说是 Sorts 对象之一。
我有一些Member具有属性的DTO emailAddress。客户端不知道,这是由来自 2 个不同实体的查询收集的信息,Account或者Invite。AMember总是具有其中之一。这工作得很好,我在 repo 中执行标准 JPA 查询并在将其转换为 DTO 之前收集所需的信息。
现在我们要对这个引用的属性进行排序。没关系。我可以创建一个查询,其中包含类似的东西ORDER BY coalesce(i.emailAddress, a.emailAddress) ASC,效果很好。如果客户端没有通过 Pageable 对象中的任何排序,我只使用这种排序,如果客户端确实通过了排序,那么我调用不同版本的查询而不使用这种默认排序。
但是现在客户想要对这个emailAddress属性进行排序,麻烦就开始了。直接将 the 传递Pageable给 theRepository不起作用,因为没有 property emailAddress。所以我想不用担心!让我们检查我的代码是否对该属性进行排序,并根据参数执行我的查询的特殊版本。
if (pageable.getSort().isSorted()) {
Sort.Order emailAddressOrder = pageable.getSort().getOrderFor("emailAddress");
if (emailAddressOrder != null) {
if (emailAddressOrder.getDirection() == Sort.Direction.ASC)
members = memberRepo.findInProjectDefaultSortAsc(projectId, skipFullName, fullName, pageable);
else
members = memberRepo.findInProjectDefaultSortDesc(projectId, skipFullName, fullName, pageable);
}
else
members = memberRepo.findInProject(projectId, …Run Code Online (Sandbox Code Playgroud)