我的spring bean有一个带有唯一强制参数的构造函数,我设法用xml配置初始化它:
<bean name="interfaceParameters#ota" class="com.company.core.DefaultInterfaceParameters">
<constructor-arg>
<value>OTA</value>
</constructor-arg>
</bean>
Run Code Online (Sandbox Code Playgroud)
然后我像这样使用这个bean,效果很好.
@Resource(name = "interfaceParameters#ota")
private InterfaceParameters interfaceParameters;
Run Code Online (Sandbox Code Playgroud)
但我想用annocations指定构造函数arg值,类似于
@Resource(name = "interfaceParameters#ota")
@contructorArg("ota") // I know it doesn't exists!
private InterfaceParameters interfaceParameters;
Run Code Online (Sandbox Code Playgroud)
这可能吗 ?
提前致谢
是否可以使用注释连接Spring MVC Interceptor,如果是这样,有人可以提供一个如何操作的示例吗?
通过注释通过注释,我指的是尽可能少地在XML配置中做.例如,我在http://www.vaannila.com/spring/spring-interceptors.html找到了这个配置文件;
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" p:interceptors-ref="loggerInterceptor" />
<bean id="loggerInterceptor" class="com.vaannila.interceptor.LoggerInterceptor" />
Run Code Online (Sandbox Code Playgroud)
你有多少配置可以逃脱?我想是一个@Autowired将删除在第2行显式声明bean的需要,但是也可以用注释去掉第1行吗?
我使用带有aspect-j注释支持的spring来允许@Loggable注释.这允许基于配置自动登录类.
我想知道我是否可以以某种方式使用此注释将slf4j Logger变量暴露给类以供直接使用,这样我就不必对以下内容执行某些操作:
Logger logger = LoggerFactory.getLogger(MyClass.class);
Run Code Online (Sandbox Code Playgroud)
如果上面因为注释而隐式可用,那将是很好的,我可以在logger.debug("...");没有声明的情况下进行.我不确定这是否可行.
我想在我在R中制作的3面小平面网格图中添加一个脚注引用.这是一个信用数据源的脚注.理想情况下,我希望它位于所有三个轴的下方和外部 - 最好是在左下方.
我使用的ggplot2也是ggsave().这意味着我不能使用grid.text()基于x11()-based 的解决方案,因为它只能在窗口上绘制,而不能添加到ggplot对象中.
使用相反png() ...code... dev.off()似乎不是一个选项,因为我需要ggsave调整参数大小,并找到这个命令产生更好,更清晰的打印(这也更快,因为我不打印到屏幕).
这是我的基本代码:
p1 <- ggplot(data, aes(date, value))
facet_grid(variable ~ .) + geom_point(aes(y =value), size=1) +
theme_bw() +
opts(title=mytitle)
print(p1)
ggsave("FILE.png",width=mywidth, height=myheight, p1, dpi=90)
Run Code Online (Sandbox Code Playgroud)
我试过了:
p1 <- ggplot(data, aes(date, value))
facet_grid(variable ~ .) + geom_point(aes(y =value), size=1) +
theme_bw() +
opts(title=mytitle)
print(p1)
grid.text(unit(0.1,"npc"),0.025,label = "Data courtesy of Me")
grid.gedit("GRID.text", gp=gpar(fontsize=7))
ggsave("FILE.png",width=mywidth, height=myheight, p1, dpi=90)
Run Code Online (Sandbox Code Playgroud)
这适当地将脚注放在x11()显示的左下角,在图的外部,但不幸的是,因为它没有应用于p1对象,所以它不会被ggsave命令保存.
我也尝试过:
p1 <- ggplot(data, aes(date, value))
facet_grid(variable …Run Code Online (Sandbox Code Playgroud) 我需要编写一些注释处理器.我发现这篇博客文章提到了如何在一般环境和Eclipse中完成.
但是我使用的是IntelliJ IDEA和Gradle,并且如果有更好的(如同,不那么繁琐)的方法,那么它就像它一样.我在找什么:
我的git和Gradle技能是初学者级别的.我很感激任何帮助这项任务.谢谢.
我在下划线中有数据库字段.我在camelcase中有实体字段.我无法改变其中任何一个.
有什么东西,也许是类级注释,我可以用来默认实体列名注释到camelcase等价物?
例如,我有一个像这样的实体:
@Entity
public class AuthorisationEntity {
@Column(name = "non_recoverable")
private BigDecimal nonRecoverable;
@Column(name = "supplier_recoverable")
private BigDecimal supplierRecoverable;
@Column(name = "refund_amount")
private BigDecimal refundAmount;
}
Run Code Online (Sandbox Code Playgroud)
我梦见这个:
@Entity
@DatabaseIsUnderscoreAndThisAnnotationConvertsThemToCamelCaseByDefault
public class AuthorisationEntity {
private BigDecimal nonRecoverable;
private BigDecimal supplierRecoverable;
private BigDecimal refundAmount;
}
Run Code Online (Sandbox Code Playgroud) 这是一个测试类:
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
public class TestAnnotations {
@interface Annotate{}
@Annotate public void myMethod(){}
public static void main(String[] args) {
try{
Method[] methods = TestAnnotations.class.getDeclaredMethods();
Method m = methods[1];
assert m.getName().equals("myMethod");
System.out.println("method inspected ? " + m.getName());
Annotation a = m.getAnnotation(Annotate.class);
System.out.println("annotation ? " + a);
System.out.println("annotations length ? "
+ m.getDeclaredAnnotations().length);
}
catch(Exception e){
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的输出:
method inspected ? myMethod
annotation : null
annotations length : 0
Run Code Online (Sandbox Code Playgroud)
我错过了通过反思使注释可见?
我是否需要一个注释处理器,即使只是检查它们的存在?
我正在为两个不同的表创建相同的实体.为了使两个实体的表映射等不同,但只将其余的代码放在一个地方 - 一个抽象的超类.最好的方法是能够在超类中注释诸如列名之类的通用内容(因为它们将是相同的),但这不起作用,因为JPA注释不是由子类继承的.这是一个例子:
public abstract class MyAbstractEntity {
@Column(name="PROPERTY") //This will not be inherited and is therefore useless here
protected String property;
public String getProperty() {
return this.property;
}
//setters, hashCode, equals etc. methods
}
Run Code Online (Sandbox Code Playgroud)
我想继承哪个,只指定特定于孩子的东西,比如注释:
@Entity
@Table(name="MY_ENTITY_TABLE")
public class MyEntity extends MyAbstractEntity {
//This will not work since this field does not override the super class field, thus the setters and getters break.
@Column(name="PROPERTY")
protected String property;
}
Run Code Online (Sandbox Code Playgroud)
任何想法或我是否必须在子类中创建字段,getter和setter?
谢谢,克里斯
我有一个内部类,它声明一个常量,并希望使用@value注释在封闭的顶级类的Javadoc中显示它的值.例如:
/**
* {@value #FOO_CONS} // this displays well
* {@value #BAR_CONS} // this does not work (checked in the latest Eclipse)
* {@value Bar#BAR_CONS} // this does not work, either
*/
public Foo {
public static final int FOO_CONS = 1;
static class Bar {
public static final int BAR_CONS = 42;
}
}
Run Code Online (Sandbox Code Playgroud)
任何想法如何在Foo类(或任何其他类,一般)的Javadoc中显示BAR_CONS的值?
我有这个代码示例:
class MeasureTextView: TextView {
constructor(context: Context?) : super(context)
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes)
companion object{
val UNIT_NONE = -1
val UNIT_KG = 1
val UNIT_LB = 0
}
fun setMeasureText(number: Float, unitType: Int){
val suffix = when(unitType){
UNIT_NONE -> {
EMPTY_STRING
}
UNIT_KG -> {
KG_SUFIX
}
UNIT_LB -> {
LB_SUFIX
}
else -> …Run Code Online (Sandbox Code Playgroud) annotations ×10
java ×6
spring ×3
autowired ×1
constants ×1
ggplot2 ×1
gradle ×1
hibernate ×1
inheritance ×1
interceptor ×1
javadoc ×1
jpa ×1
kotlin ×1
r ×1
r-grid ×1
reflection ×1
slf4j ×1
spring-mvc ×1