Tag: 注释

package-info.java包注释会影响所有类,包括子包中的类

我想在我的所有课程上应用注释,我正在尝试最好的方法。 到目前为止,我坚持使用package-info.java文件,该文件可以注释整个包,但不包含子包中包含的类文件。 除了在我的项目中添加100个相同的package-info.java文件(仅包含一个注释)之外,还有更有效的方法吗? 谢谢

javax.annotations.Nonnull上的TypeNotPresentException

我已将maven surefire插件(2.17)添加到我们的项目中,但构建失败并出现以下错误。 Error injecting: org.apache.maven.plugin.surefire.SurefirePlugin java.lang.TypeNotPresentException: Type javax.annotation.Nonnull not present at com.ibm.oti.reflect.AnnotationHelper.getAnnotation(AnnotationHelper.java:39) at com.ibm.oti.reflect.AnnotationHelper.getDeclaredAnnotations(AnnotationHelper.java:51) at com.ibm.oti.reflect.Method.getDeclaredAnnotations(Method.java:35) at java.lang.reflect.Method.getDeclaredAnnotations(Method.java:719) at java.lang.reflect.AccessibleObject.getAnnotations(AccessibleObject.java:187) at com.ibm.oti.reflect.Method.getAnnotation(Method.java:21) at java.lang.reflect.Method.getAnnotation(Method.java:693) at com.google.inject.spi.InjectionPoint.getAtInject(InjectionPoint.java:478) at com.google.inject.spi.InjectionPoint.getInjectionPoints(InjectionPoint.java:676) at com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields(InjectionPoint.java:366) at com.google.inject.internal.ConstructorBindingImpl.getInternalDependencies(ConstructorBindingImpl.java:165) at com.google.inject.internal.InjectorImpl.getInternalDependencies(InjectorImpl.java:609) at com.google.inject.internal.InjectorImpl.cleanup(InjectorImpl.java:565) at com.google.inject.internal.InjectorImpl.initializeJitBinding(InjectorImpl.java:551) at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:865) at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:790) at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:278) at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:210) at com.google.inject.internal.InjectorImpl.getProviderOrThrow(InjectorImpl.java:986) at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1019) at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:982) at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1032) at […]

通常可重复使用的注释或公共注释?

是否有可用的常用注释? 与commons-lang相似? 如果没有,您是否看到任何有效使用annontations(不是内置注释)作为任何开源应用程序开发的一部分。 我记得Mifos正在使用它进行交易。 磨憨

在JUnit测试时,对@Component类进行排除过滤?

是否可以排除@Component注释类? 我想从JUnit测试中排除一个特殊类。 我的项目有一个用@Component注释的类xEventHandler ,我不希望spring在junit测试时使用这个类。 我的ApplicationTestContext.xml如下所示: … … 但是,由于@Component注释,类被输入(例如,当我从该类中删除@Component时工作)。 我该怎么办呢?

Java注释重载?

在我的项目中,我已经定义了类似于以下内容的注释: (省略@Retention , @Target为了简洁) public @interface DecaysTo { String[] value(); } 自从最初编写它以来,我们的需求已经改变,我现在已经定义了一个枚举,我希望能够使用它来代替字符串: public enum Particle { ELECTRON, ANTIELECTRON, NEUTRINO, ANTINEUTRINO, … } 为了避免更新此批注的每个实例,我希望能够使用 String 或 enum Particle的成员构造批注, 而无需更新此批注的每个实例以指定属性。 但是,由于我们定义了注释的属性,而不是构造函数,因此似乎不可能重载它。 // In a perfect world, either of these would work … public @interface DecaysTo { String[] value(); Particle[] value(); } @DecaysTo({“Electron”, …}) @DecaysTo({Particle.ELECTRON, …}) // without […]

Eclipse RCP 4 – 处理程序方法参数

我目前正在研究新的Eclipse RCP框架,并对处理程序有疑问。 在RCP 3.xa处理程序类中需要实现一个接口,所以给出了方法。 在RCP 4中,处理程序类不需要实现接口。 相反,你注释方法。 例如,如果您有Vogellas Tutorial中的ExitHandler ,则会有@Execute注释。 如您所见,传递了IWorkbench参数。 package com.example.e4.rcp.todo.handler; import org.eclipse.e4.core.di.annotations.Execute; import org.eclipse.e4.ui.workbench.IWorkbench; public class ExitHandler { @Execute public void execute(IWorkbench workbench) { workbench.close(); } } 我现在的问题是:在使用某些注释时,我如何知道传递了哪些参数? 在这种情况下,我如何知道我得到的是IWorkbench对象而不是Window对象? 事实上,我可以在没有参数的情况下注释方法,但它仍然会被执行。 某处有文件吗? Eclipse e4 Tools似乎也不支持我…

如何在使用Spring @Value时进行简单的属性validation

如果${service.property}不是空字符串,如何检查,抛出某种可读exception,我如何检查? 它必须在Bean创建期间发生。 @Component public class Service { @Value(“${service.property}”) private String property; } 我正在寻找最简单的方法(最少编写代码)。 如果使用注释会很棒。 我目前的解决方案是在属性的setter中执行“手写”validation,但对于这样简单的事情来说,这是一个太多的代码。 提示:我找了一些使用SpEL的方法,因为我已经在@Value使用了它,但是到目前为止我发现它并不那么容易/干净。 但本来可以忽略一些东西。 澄清:预期的行为是,应用程序无法启动。 目标是确保所有属性都已设置,尤其是字符串属性不为空 。 错误应该清楚地说,缺少什么。 我不想设置任何默认值! 用户必须全部设置。

在Spring中按顺序实例化bean?

是否可以在Spring中设置实例化顺序? 我不想使用@DependsOn ,我不想使用Ordered接口。 我只需要一个实例化的命令。 @Order注释的以下用法不起作用: import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.Order; /** * Order does not work here */ public class OrderingOfInstantiation { public static class MyBean1 {{ System.out.println(getClass().getSimpleName()); }} public static class MyBean2 {{ System.out.println(getClass().getSimpleName()); }} @Configuration public static class Config { @Bean @Order(2) public MyBean1 bean1() { return new MyBean1(); } […]

强制带注释的类包含带注释的字段

是否可以强制(在编译时)带注释的类具有带注释的字段? 我有这个注释: @Target(value = ElementType.TYPE) @interface MyClass {} @Target(value = ElementType.FIELD) @interface MyField {} 现在我希望像这样的类的编译失败: @MyClass class Customer { } 这应该工作: @MyClass class Customer { @MyField String text; }

没有实现绑定 – Java Guice

新手在这里试图使用一个虚拟Java Facebook应用程序,使用Guice将数据库dependency injectionFacebook工厂,但继续让Guice错误告诉我: ###在查找使用@ com.example.storage.annotations.SystemDb注释的com.example.storage.Db时,没有使用@ com.example.storage.annotations.SystemDb()注释的com.example.storage.Db的实现。 ()for com.example.facebook.client.exceptions.FacebookExceptionHandlerDb中的参数0,位于com.example.facebook.client.guice.FacebookClientModule.configure ###无法在com.example.facebook.statsd.StatsdClient中找到合适的构造函数。 类必须有一个(也是唯一一个)使用@Inject注释的构造函数或一个非私有的零参数构造函数。 at com.example.facebook.statsd.StatsdClient.class,同时在com.example.facebook.client.exceptions.FacebookExceptionHandlerDb中找到参数1的com.example.facebook.statsd.StatsdClient。 com.example.facebook.client.guice.FacebookClientModule.configure 应用代码: app.java package com.example.facebook; import com.google.inject.Guice; import com.restfb.Connection; import com.restfb.types.Post; import com.example.facebook.client.FacebookClientFactory; import com.example.facebook.client.RobustFacebookClient; import com.example.facebook.client.guice.FacebookClientModule; import com.example.facebook.statsd.StatsdClient; public class App { public static void main ( String[] args ) { final FacebookClientFactory facebookClientFactory = Guice.createInjector(new FacebookClientModule()).getInstance(FacebookClientFactory.class); //error from line above final […]