我正在尝试使用spring的UriComponentsBuilder来生成一些用于oauth交互的URL.查询参数包括诸如回调URL和其中包含空格的参数值之类的实体.
试图使用UriComponentBuilder(因为现在不推荐使用UriUtils)
UriComponentsBuilder urlBuilder = UriComponentsBuilder.fromHttpUrl(oauthURL);
urlBuilder.queryParam("client_id", clientId);
urlBuilder.queryParam("redirect_uri", redirectURI);
urlBuilder.queryParam("scope", "test1 test2");
String url = urlBuilder.build(false).encode().toUriString();
Run Code Online (Sandbox Code Playgroud)
不幸的是,虽然scope参数中的空格已成功替换为'+',但redirect_uri参数根本不是url编码的.
例如,
redirect_uri=https://oauth2-login-demo.appspot.com/code
Run Code Online (Sandbox Code Playgroud)
应该结束了
redirect_uri=https%3A%2F%2Foauth2-login-demo.appspot.com%2Fcode
Run Code Online (Sandbox Code Playgroud)
但没有动过.潜入代码,特别是org.springframework.web.util.HierarchicalUriComponents.Type.QUERY_PARAM.isAllowed(c):
if ('=' == c || '+' == c || '&' == c) {
return false;
}
else {
return isPchar(c) || '/' == c || '?' == c;
}
Run Code Online (Sandbox Code Playgroud)
明确地允许':'和'/'字符,这不应该是口香糖.它必须做一些其他类型的编码,虽然对于我的生活,我无法想象什么.我在这里吠叫错了树吗?
谢谢
我最近升级到3.2版本,并注意到AnnotationMethodHandlerAdapter已经弃用了赞成RequestMappingHandlerAdapter.所以我重新配置使用新类,完成MessageConverter我需要的自定义.一切都很好.
但是,当试图点击带注释的URL支持时Controller,我收到一个错误:
[java] javax.servlet.ServletException: No adapter for handler [my.company.TagController@1c2e7808]: The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler
[java] at org.springframework.web.servlet.DispatcherServlet.getHandlerAdapter(DispatcherServlet.java:1128)
[java] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:903)
[java] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
Run Code Online (Sandbox Code Playgroud)
在调试调度程序时,特别是Dispatcher.getHandlerAdapter()方法,它找到了我的HandlerAdapter,但是AbstractHandlerMethodAdapter.supports()调用它需要一个MethodHandler:
public final boolean supports(Object handler) {
return handler instanceof HandlerMethod && supportsInternal((HandlerMethod) handler);
}
Run Code Online (Sandbox Code Playgroud)
并且控制器不是HandlerMethod.该AnnotatedMethodHandlerAdapter的支持方法..好,不同的(作品仍然!)
public boolean supports(Object handler) {
return getMethodResolver(handler).hasHandlerMethods();
}
Run Code Online (Sandbox Code Playgroud)
所以我显然不能简单地升级到新类...我缺少一些额外的配置,但文档并没有真正帮助我.有任何想法吗?
谢谢.
有没有人碰巧构造一个PropertySource,它使用远程源(例如数据库)从中检索属性值。想法是构造一个PropertySource(需要一些连接信息,例如主机/端口),然后将其插入PropertySourcePlaceholderConfigurer。
问题似乎是鸡肉和鸡蛋的问题。如何获取连接信息到PropertySource?我可以首先使用配置实例化PropertySourcePlaceholderConfigurer,以使用远程主机和端口属性加载属性文件,然后再实例化PropertySource并将其注入配置器。但是,我似乎无法找到一种方法来确保要实例化的第一个bean(并迅速注入到配置程序中)是我的属性来源。我需要这样做,因为,当然,所有其他bean都取决于远程属性。
我试图检查(在字节码级别,ASM)实现某些特定接口(在本例中为java.sql.Connection)的类,并发现在某些情况下,库具有另一个接口,该接口扩展了我的接口集。 ..然后它们的类实现THAT接口。(在这种情况下,新的扩展接口com.mysql.jdbc.Connection扩展了java.sql.Connection,然后扩展了它们的实现,例如ConnectionImpl实现了com.mysql.jdbc.Connection。)因此,我错过了将ConnectionImpl标识为目标类的想法。
因此,结果是我在加载类时需要将com.mysql.jdbc.Connection标识为“有趣的”接口。但是我看不到如何通过接口而不是普通类来标识类。ClassReader中是否有某些东西可以给我这种信息?
我正在尝试创建一个应用程序überjar,但由于依赖于spring框架而遇到了问题.特别是,xml架构的命名空间是有问题的.你得到臭名昭着的NamespaceHandler问题:
Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/c]
Run Code Online (Sandbox Code Playgroud)
对于创建(简单)uber jar,使用ant创建一个bundle jar,但是如果你有spring依赖,那么这不起作用,因为spring jar有spring.handlers,spring.schemas和spring.tooling等文件.许多jar文件的META-INF目录.我认为,命名空间解析依赖于这些文件.
überjar似乎以某种方式包含所有必要的文件,但我猜测运行时只看到一个.
例如,我的超级罐的jar -tf显示(部分)
META-INF/spring.handlers
META-INF/spring.schemas
META-INF/spring.tooling
META-INF/license.txt
META-INF/notice.txt
META-INF/spring.factories
META-INF/spring.handlers
META-INF/spring.schemas
META-INF/spring.tooling
META-INF/license.txt
META-INF/notice.txt
META-INF/license.txt
META-INF/notice.txt
META-INF/spring.handlers
META-INF/spring.schemas
META-INF/spring.tooling
META-INF/license.txt
META-INF/notice.txt
META-INF/license.txt
Run Code Online (Sandbox Code Playgroud)
那么:问题..有没有办法创造一个有弹簧罐捆绑在里面的超级罐?我需要合并META-INF文件吗?任何人都有与蚂蚁构建文件合并的经验吗?
我有兴趣从 Spring 获取 bean 列表ApplicationContext。特别是这些是Ordered豆类
@Component
@Order(value=2)
Run Code Online (Sandbox Code Playgroud)
而且我在一些未启用 Spring 的遗留代码中,所以我制造了一种方法来获取ApplicationContext. 对于春豆,我知道我可以这样做:
@Bean
public SomeType someType(List<OtherType> otherTypes) {
SomeType someType = new SomeType(otherTypes);
return someType;
}
Run Code Online (Sandbox Code Playgroud)
但ApplicationContextonly 提供了一种getBeansOfType返回无序映射的方法。我试过,getBeanNames(type)但这也会返回无序的东西。
我唯一能想到的是创建一个只包含 List 的虚拟类,为该虚拟类创建一个 bean 并检索有序列表:
public class DumbOtherTypeCollection {
private final List<OtherType) otherTypes;
public DumbOtherTypeCollection(List<OtherType) otherTypes) {
this.otherTypes = otherTypes;
}
List<OtherType> getOrderedOtherTypes() { return otherTypes; }
}
@Bean
DumbOtherTypeCollection wasteOfTimeReally(List<OtherType otherTypes) {
return new DumbOtherTypeCollection(otherTypes);
}
....
applicationContext.getBean(DumbOtherTypeCollection.class).getOrderedOtherTypes();
Run Code Online (Sandbox Code Playgroud)
只是希望我能做得更好。
我在spring xml配置文件中使用c:和p:名称空间,但是如何在此调用中传递null?我知道什么时候不使用c:名称空间,我可以使用:
<constructor-arg><null/></constructor-arg>
Run Code Online (Sandbox Code Playgroud)
但是我该怎么做呢:
c:myArgument=?
Run Code Online (Sandbox Code Playgroud) 我有两个服务器系统...一个托管应用程序,另一个托管身份验证/授权。当应用程序检测到用户尚未登录时,它将重定向到身份验证服务器,并将用户最初请求的URL作为参数传递,以便在身份验证之后,用户将被重定向回应用程序服务器到最初请求的确切网址。
但是,如果该原始URL包含#,则将执行整个例程。看来浏览器正在解码url编码的参数,因此,将#号之后的所有内容都放到了地板上。我已经在Chrome,Safari和Firefox上尝试过此操作。
例:
原始网址:
https://xxx.com/#/main/by-users?param1=53¶m2=13¶m3=39
Run Code Online (Sandbox Code Playgroud)
重定向网址:
https://yyy.com/signin/?returnURL=https%3A%2F%2Fxxx.com%3A80%2F%23%2Fmain%2Fby-users%3Fparam1%3D53%26param2%3D13%26param3%3D39
Run Code Online (Sandbox Code Playgroud)
浏览器显示:
https://yyy.com/signin/?returnURL=https%3A%2F%2Fxxx.com%2F#/main/by-users?param1=53¶m2=13¶m3=39
Run Code Online (Sandbox Code Playgroud)
如您所见,包括#和之后的所有内容均已解码。因此,服务器永远不会获得完整的“ returnURL”参数值。基本上就是
https://xxx.com/
Run Code Online (Sandbox Code Playgroud)
这一定是某个规范的一部分,尽管似乎应该疯狂地对已编码的#进行解码和处理,就好像它从来没有被编码过一样。但是如何解决这个问题?
谢谢。