我不明白为什么Java注释中没有继承,就像Java类一样.我认为这将非常有用.
例如:我想知道给定的注释是否是验证器.通过继承,我可以反复地浏览超类,以了解此注释是否扩展了ValidatorAnnotation.否则,我该怎样才能做到这一点?
那么,任何人都可以给我这个设计决定的理由吗?
我想更改二进制文件的修改时间戳.这样做的最佳方式是什么?
打开和关闭文件是一个不错的选择吗?(我需要一个解决方案,在每个平台和JVM上更改时间戳的修改).
有可能在Spring中获取给定对象的代理吗?我需要调用子类的函数.但是,显然,当我直接打电话时,方面不适用.这是一个例子:
public class Parent {
public doSomething() {
Parent proxyOfMe = Spring.getProxyOfMe(this); // (please)
Method method = this.class.getMethod("sayHello");
method.invoke(proxyOfMe);
}
}
public class Child extends Parent {
@Secured("president")
public void sayHello() {
System.out.println("Hello Mr. President");
}
}
Run Code Online (Sandbox Code Playgroud)
我找到了实现这一目标的方法.它有效,但我认为不是很优雅:
public class Parent implements BeanNameAware {
@Autowired private ApplicationContext applicationContext;
private String beanName; // Getter
public doSomething() {
Parent proxyOfMe = applicationContext.getBean(beanName, Parent.class);
Method method = this.class.getMethod("sayHello");
method.invoke(proxyOfMe);
}
}
Run Code Online (Sandbox Code Playgroud) 在Spring MVC中,我可以使用JstlView的exposedContextBeanNames(或exposeContextBeansAsAttributes)在JSP中访问我的bean.例如,然后,在我的JSP中我可以编写($ {properties.myProperty).但是,当相同的JSP是切片视图的一部分时,无法访问这些属性.是否可以正确配置Tiles或以其他方式访问这些属性?
我正在使用Spring MVC 3.0.2和Tiles 2.2.1.这是我的一些配置:
<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="order" value="1"/>
<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" />
</bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="order" value="2"/>
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
<property name="exposedContextBeanNames">
<list><value>properties</value></list>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
编辑:我已经实施了Skaffman的解决方案.
TilesExposingBeansViewResolver.java:
package es.kcsolutions.util.spring.servlet.view;
import org.springframework.web.servlet.view.*;
public class TilesExposingBeansViewResolver extends UrlBasedViewResolver {
private Boolean exposeContextBeansAsAttributes;
private String[] exposedContextBeanNames;
public void setExposeContextBeansAsAttributes(boolean exposeContextBeansAsAttributes) {
this.exposeContextBeansAsAttributes = exposeContextBeansAsAttributes;
}
public void setExposedContextBeanNames(String[] exposedContextBeanNames) {
this.exposedContextBeanNames = exposedContextBeanNames;
}
@Override
protected AbstractUrlBasedView buildView(String viewName) throws …Run Code Online (Sandbox Code Playgroud) 在以下情况下,我需要使用与方法匹配的切入点创建方面:
我认为前两个条件很简单,但我不知道是否有可能用Spring完成第三个条件.如果不是,也许我可以将其改为:
你认为有可能实现这个目标吗?性能会好吗?
谢谢
编辑:匹配方法的一个例子.如您所见,MyMethod没有注释(但它可以).
@Controller
public class MyClass {
public void MyMethod (String arg0, @MyParamAnnotation Object arg1, Long arg3) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:我最终使用的解决方案,基于@Espen答案.正如你所看到的,我改变了我的条件:class实际上并不需要成为@Controller.
@Around("execution(public * * (.., @SessionInject (*), ..))")
public void methodAround(JoinPoint joinPoint) throws Exception {
...
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Java开发桌面应用程序.我想在系统托盘上放置一个图标(带有上下文菜单)(在Mac OS中称为菜单附加功能).Java 6支持在Windows和Linux中执行此操作,但它在Mac Os中不起作用.
我已经看到一些应用程序在所有三个操作系统(例如DropBox)中执行我想要的操作,但我不知道它们是否是用Java编写的.
我怎样才能做到这一点?
如果在Java中不可能,是否还有其他跨平台语言可以做到这一点?
谢谢.
我们有两个相同的Oracle Exadata四分之一机架,每个机架运行一对数据库实例.我的湿手指在风中的性能测试表明,一个人的速度是另一个人的四分之一.
是否有一组可以使用计时器运行的SQL查询,可以更加科学地比较两个服务器之间的查询性能?
我知道我可以编写一组查询.我想知道是否已存在半标准基准集.类似于一些表创建查询,然后是迭代插入语句(大量随机数据),索引,约束,触发器,函数,proc和视图创建脚本(最好包括物化视图),然后是一堆扩展引擎的复杂查询加入连接,触发器触发,函数和proc调用等...同时将性能统计信息写入某些临时表?
有人遇到过这样的库/工具/脚本集吗?
我不知道这是否是一个恰当的问题.
众所周知,在CAP定理中,"A"表示"可用性".在维基百科上,"可用性"的解释是:
Availability: a guarantee that every request receives a response about whether it was successful or failed
Run Code Online (Sandbox Code Playgroud)
但是,从工程角度来看,没有ABSOLUTE可用性.我们只能说系统的可用性是5'9'(99.999%),甚至是8'9',但我们不能说系统的可用性是100%,100%可用系统实际上不会退出即使系统有数百万个重复节点,对吧?
CAP定理证明了没有一个系统可以同时满足这3个要求.我的问题是,如果一个系统声称同时满足"A"和"P",那么这个"A"的准确含义是什么?6'9'甚至更高?
有时我希望字段上的注释在一行中,有时在每行中.是否有任何方法可以使Eclipse格式化程序忽略这些注释并让线条像我一样中断?
这是实际的代码:
@RequestMapping(value = "/competitors/{id}", method = RequestMethod.GET)
public Competitor getCompetitor(@PathVariable("id") long id)
{
Competitor competitor = competitorService.getCompetitorById(id);
if (null == competitor)
{
EmptyResultDataAccessException e = new EmptyResultDataAccessException(1);
logger.log(Level.WARN, e.getMessage());
throw e;
}
return competitor;
}
@RequestMapping(value = "/competitors/{id}", method = RequestMethod.DELETE)
public String deleteCompetitor(@PathVariable("id") long id)
{
Competitor competitor = new Competitor();
competitor.setId(id);
competitorService.deleteCompetitor(competitor);
return "Solid gone!";
}
Run Code Online (Sandbox Code Playgroud)
向/ compet/200发送DELETE请求会导致错误:
"HTTP状态405 - 不支持请求方法'DELETE'"
来自Spring的日志记录确认无法找到此方法的路由:
5559 [tomcat-http--3] DEBUG org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'dispatcher' processing DELETE request for [/vrsboserver/competitors/200] 5562 [tomcat-http--3] …Run Code Online (Sandbox Code Playgroud) java ×6
spring ×4
annotations ×2
aop ×2
spring-mvc ×2
aspectj ×1
database ×1
eclipse ×1
exadata ×1
file ×1
formatting ×1
http ×1
inheritance ×1
jsp ×1
macos ×1
oracle ×1
rest ×1
servlets ×1
spring-aop ×1
sql ×1
system-tray ×1
tiles ×1
touch ×1