如何反射获取所有控制器的列表(最好,如果不仅注释,但也在xml中指定),匹配Spring MVC应用程序中的一些特定URL?
如果只注释,
@Autowired
private ListableBeanFactory listableBeanFactory;
...
whatever() {
Map<String,Object> beans = listableBeanFactory.getBeansWithAnnotation(RequestMapping.class);
// iterate beans and compare RequestMapping.value() annotation parameters
// to produce list of matching controllers
}
Run Code Online (Sandbox Code Playgroud)
可以使用,但在更一般的情况下,当在spring.xml配置中指定控制器时该怎么办?以及如何处理请求路径参数?
它是如何能够提供三个功能:msgpack_pack,msgpack_unpack和msgpack_object(?还有,什么是他们的意义,精确地)为用户定义的C++类(以同样的方式MSGPACK_DEFINE做它用在非阵列POD/UD类型)包含普通老式数据数组(例如dobule[]或者char[]),所以我的类可以很好地使用更高级别的类,在地图或向量中包含这个类?
是否有任何为您自己的类或至少msgpack C++ api文档实现它们的示例?
我发现可能的API参考的唯一链接是http://redmine.msgpack.org/projects/msgpack/wiki ; 但它现在已经死了.
说,我有一个类似的结构
struct entity {
const char name[256];
double mat[16];
};
Run Code Online (Sandbox Code Playgroud)
什么是msgpack_*成员函数呢?
说,我有一个带有以下web.xml条目的Spring MVC应用程序:
<error-page>
<error-code>404</error-code>
<location>/error/404</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)
并跟随错误页面控制器:
@RequestMapping({"","/"})
@Controller
public class RootController {
@RequestMapping("error/{errorId}")
public String errorPage(@PathVariable Integer errorId, Model model) {
model.addAttribute("errorId",errorId);
return "root/error.tile";
}
}
Run Code Online (Sandbox Code Playgroud)
现在用户请求不存在的URL/user/show/iamnotauser,它触发了错误页面控制器.如何从RootController的errorPage()方法获取这个不存在的'/ user/show/iamnotauser'URL以将其放入模型并显示在错误页面上?
我试图在收到SIGINT信号时正确地终止我的多线程C++ 11应用程序(^C它是),但由于某种原因它不会传播到子线程,尽管主线程很好地响应它.
对于instnce(如下面的代码示例中所示),如果我们在线程内部有一些阻塞函数(例如sleep()),^C如果你使用比如安装任何SIGNT钩子,它将取消你的所有控制权sigaction().
有没有办法解决或解决这种行为?有没有办法将主接收信号传播到子线程?
编辑:sleep()用C++ 11 替换POSIXstd::this_thread::sleep_for()
#include <iostream>
#include <thread>
#include <chrono>
#include <signal.h> // for sigaction() function
static int signaled = 0;
void threaded_foo() {
while (!signaled) {
// pressing ^C now will not lead to correct termination, because we are
// sleeping for a long time (100500 seconds) and do not respond to
// SIGINT for some tricky reason i am looking a bypassage for. …Run Code Online (Sandbox Code Playgroud) 我希望在我的无状态或手动维护的状态Spring MVC应用程序中禁用Jetty 9中的各种会话跟踪功能,但我找不到任何显示如何执行此操作的工作示例.
我试过以下/WEB-INF/spring-config.xml标签:
...
<security:http use-expressions="true"
disable-url-rewriting="true"
create-session="stateless">
...
Run Code Online (Sandbox Code Playgroud)
与/WEB-INF/jetty-web.xml战争中的以下描述符一起:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Get name="sessionHandler">
<Get name="sessionManager">
<Set name="usingCookies" type="boolean">false</Set>
</Get>
</Get>
</Configure>
Run Code Online (Sandbox Code Playgroud)
但是,无论何时尝试打开我的应用程序的任何页面,我仍然会获得JSESSIONID cookie.任何提示为什么以及如何解决它?
我开始需要发明一种新型的注释,其中一个字段是 Spring 表达式语言(又名 SpEL)表达式字符串。
经过一番谷歌搜索和检查现有类后,我发现评估表达式的方式可能是这样的(如果我有任何错误,请纠正我):
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression("isAnonymous()"); // well, this is only an example
SecurityExpressionRoot context = ... obtaining the instance of subclass of SecurityExpressionRoot ...
System.out.println(exp.getValue(context)); // just an example
Run Code Online (Sandbox Code Playgroud)
但问题是:最适合我的情况的 MethodSecurityExpressionRoot 是包本地的。甚至有一项在 Spring Security JIRA 中公开的任务,一年来没有得到开发人员的任何关注。
而且,即使它不是包的地方,我还有哪里获得方法的对象弱的理解setTrustResolver,setRoleHierarchy和setPermissionEvaluator的SecurityExpressionRoot类,它似乎有需要为它的正常运作。
所以,我的问题是:如何正确获取正确的SecurityExpressionRoot-subclass 实例以及如何使用所需的对象填充它?
我正在使用libuv进行广泛的网络交互应用程序,我担心重新使用已分配内存的哪些技术可以同时使用libuv回调执行的高效和安全.
在非常基本的层,暴露给libuv用户,需要在设置句柄阅读器的同时指定缓冲区分配回调:
UV_EXTERN int uv_read_start(uv_stream_t*, uv_alloc_cb alloc_cb, uv_read_cb read_cb);
Run Code Online (Sandbox Code Playgroud)
这里uv_alloc_cb是
typedef void (*uv_alloc_cb)(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf);
Run Code Online (Sandbox Code Playgroud)
但问题是:每次通过句柄传递新消息时调用此内存分配回调(例如,uv_udp_t接收到来自句柄的每个UDP数据报),并且每个传入UDP数据报的新缓冲区的直接前向分配似乎非常非内存-明智的.
所以我要求在可能的情况下重新使用相同的分配内存的常见C技术(可能在libuv回调系统引入的延迟执行上下文中).
另外,如果可能的话,我想保持便携式窗户.
笔记:
阅读http://nikhilm.github.io/uvbook/filesystem.html,我注意到了以下短语uvtee/main.c - Write to pipe:
我们制作一个副本,这样我们就可以从两次调用中释放两个缓冲区,使它们彼此独立.虽然这样的演示程序可以接受,但您可能需要更智能的内存管理,例如引用计数缓冲区或任何主要应用程序中的缓冲池.
但我无法找到任何涉及libuv缓冲区上的引用计数的解决方案(如何正确执行?)或libuv环境中缓冲池的显式示例(是否有任何库?).
我有以下 SQL 架构布局:
-- postgresql82+ syntax
create table AudioTracks (
id serial primary key
, name text
, size integer
, filePath text
, additionDate timestamp default now()
);
create table Genres (
id serial primary key
, name text unique -- here is the unique constraint which troubles me
, description text
, additionDate timestamp default now()
);
create table AudioTrackGenre (
genreId integer references Genres (id) unique
, audioTrackId integer references AudioTracks (id) unique
, additionDate timestamp default …Run Code Online (Sandbox Code Playgroud) 我有两个div,一个嵌套在另一个div中,我希望将内部div向外(向上)移到外部div上,然后将其滑入。
标记看起来像这样:
<div class="body">
<div class="inner">Green is variable-height text which slides in on viewport hover</div>
Blue is a viewport (<body>, visible part of a page), which content should be compressed upon green slide-in
</div>
Run Code Online (Sandbox Code Playgroud)
和(一点伪)CSS:
.body {
background: #aaf;
height: 300px;
width: 300px;
overflow: hidden;
}
.inner, .body:hover .inner {
-webkit-transition:all linear 0.2s;
transition:all linear 0.2s;
}
.inner {
background: #afa;
width: 300px;
margin-top:-some-magic-to-get-this-div-height;
}
.body:hover .inner {
margin-top: 0;
}
Run Code Online (Sandbox Code Playgroud)
我想得到一个最终结果动画,而无需使用固定高度的绿色div:

另外,在jsfiddle上,该示例(高度值的猜测和硬编码为2.5em)可以进行以下实验:
http://jsfiddle.net/n7vyLoh4/20/
它可以部分地实现我想要的东西,使用过渡最大高度,而不是过渡边距,过渡max-height: 0; - …
我有一个简单的bean定义注册表单模型上的用户凭据:
public class UserCreds {
@Length(min=1, max=50)
@NotEmpty
private String username;
@Email
private String email;
@NotEmpty
@Length(min=1, max=50)
private String password;
private String passwordConfirm;
... only obvious getters and setters below this line ...
}
Run Code Online (Sandbox Code Playgroud)
我在"userCreds"模型属性下传递它的实例,所以我有一个以下本地化包:
NotEmpty.userCreds.username=Username is required
NotEmpty.userCreds.password=Passsword is required
Length.userCreds.username=Username length must be between {2} and {1} symbols
Length.userCreds.password=Password length must be between {2} and {1} symbols
Email.userCreds.email=Ill-formed e-mail address
Run Code Online (Sandbox Code Playgroud)
它的工作原理!
这里的问题是:我不想使用这个神秘的{N}占位符,它们可能会偶尔改变它们的位置(在'max'之上的捆绑绑定到{1}并且'min'绑定到{2},这是在最不明显的定位)我希望使用注释的全名,如
Length.userCreds.username=Username length must be between {min} and {max} symbols
Run Code Online (Sandbox Code Playgroud)
(这是行不通的 - 当我尝试它 - 我得到java.lang.IllegalArgumentException: …
java spring localization hibernate-validator bean-validation
我有一个Base班级,很少有派生的孩子,名字ChildN.
我也有一个Container类,有ChildN特定的方法.
最后我有一个主类,我希望将所有Base通用逻辑转换为辅助方法,但在这个逻辑的中间某处我可能需要将一个ChildN特定的对象放入正确的Container类方法中.我怎么做?如何hassleSafeAdder使用正确的ChildN类型专门调用,所以它可以在这个方法中访问,我可以转换它,或做一些其他的事情,使得能够正确地将对象调度到正确的方法?
// base class
public static class Base { }
// derived classes
public static class Child1 extends Base { }
public static class Child2 extends Base { }
public static class Child3 extends Base { }
public static class Child4 extends Base { }
// class with derived types in method signature
public static class Container {
public void …Run Code Online (Sandbox Code Playgroud) java ×5
spring ×5
spring-mvc ×3
c++ ×2
api ×1
c ×1
c++11 ×1
css ×1
generics ×1
hibernate ×1
html ×1
jetty ×1
libuv ×1
localization ×1
markup ×1
memory ×1
msgpack ×1
polymorphism ×1
reflection ×1
signals ×1
spring-el ×1
stylesheet ×1
syntax ×1