草庐IT

Controller注解

全部标签

java - Play框架-测试POST Controller 方法

我想在我的Controller中测试我的一个POST方法,所以我写了这样的东西:@TestpublicvoidshouldSaveNewCollectionToDatabase(){Stringbody="{\"name\":\"collectionName\",\"owner\":{}}";JsonNodejson=Json.parse(body);FakeRequestrequest=newFakeRequest(POST,"/rest/collections/add").withJsonBody(json);Resultresult=callAction(controllers.

java - ContextConfiguration RunWith WebAppConfiguration 注解一起

我有注释这些注释的类:@ContextConfiguration(locations={"classpath:pathToXml.xml"})@RunWith(SpringJUnit4ClassRunner.class)@WebAppConfiguration你能解释一下我在类里面添加这些注释后有什么特点吗? 最佳答案 您将获得@WebAppConfiguration配置javadoc中描述的功能。WebApplicationContext主要改变了资源的加载方式,即具有未指定资源前缀的资源将从src/main/webapp或从va

java - Spring @RequestParam 和 Controller 接口(interface)

我对@RequestParam(value="someValue")的行为感到困惑。在docs据说Whenusingcontrollerinterfaces(e.g.forAOPproxying),makesuretoconsistentlyputallyourmappingannotations-suchas@RequestMappingand@SessionAttributes-onthecontrollerinterfaceratherthanontheimplementationclass.如果我将@RequestParam放在我的Controller接口(interface)

java - 如何在运行时删除 Java 注解(可能使用反射)?

我们正在构建一个工具(供内部使用),只有在从我们的源代码中删除javax.persistence.GeneratedValue注释时它才能工作(我们在工具中设置Id,由于GeneratedValue注释而被拒绝)。..但对于正常操作,我们需要此注释。如何在运行时删除Java注解(可能使用反射)?这是我的课:@EntitypublicclassPersistentClass{@Id@GeneratedValue(strategy=GenerationType.AUTO)privatelongid;//...Otherdata}这是我希望能够在运行时将其更改为:@Entitypublicc

java - 如何使用@RequestMapping 在 Spring MVC Controller 中优化我的代码?

在我的Controller中,我的Controller方法名称等于请求映射url。例如,/list等于方法名称list。是否有通用的处理程序方法来缩短我的代码?我不想以这种方式编写每个Controller和方法。我记得.netmvc有一种常见的配置方式。SpringMVC怎么样?@Controller@RequestMapping(value="/fooController")publicclassFooController{@RequestMapping("/list")publicStringlist(...){...}@RequestMapping("/save")publicS

java - 从 Taglet 访问 Java 注解

我正在做一个项目,我们有一些自定义的Taglet类,用于修改Javadoc(例如链接到SVN中的源代码,添加引用)等等。我们想要做的事情之一要做的是能够获取源中使用的注释并操作来自它们的信息。似乎Taglet接口(interface)没有提供一种简单的方法来访问Java源代码中的注释。有人知道这是否可能吗?我正在使用JDK1.5 最佳答案 如果您的taglet是从标准doclet调用的,您可以访问其内部状态:importcom.sun.tools.doclets.standard.Standard;ClassDoccurrentcd

java - 在注解上使用默认的类文字值

我想用下面的注释来注释给定bean类的一些字段:@Target({FIELD})@Retention(RUNTIME)public@interfaceProcess{Classusing()defaultDefaultImplStrategy.class;}在不深入领域的情况下,每个带注释的属性都需要在其上定义一个ProcessingStrategy,因此需要在注释上使用using()属性。这很好,并且按照我希望的方式工作。我还想指定策略的默认实现,大多数时候使用(下面定义的默认值)。这在Eclipse中运行良好。但是,当我尝试使用常规JDK​​(通过maven调用)编译它时,出现以下

java - 如何通过在 Java 中检索异常方法来获取注解?

这次我想从抛出的异常中获取注解。我的示例代码是这样的:publicclassP{@MyAnnotation(stringValue="FirstType",intValue=999)publicvoidtest()throwsException{//...thrownewNullPointerException();}@MyAnnotation(stringValue="SecondType",intValue=111)publicvoidtest(inta)throwsException{//...thrownewNullPointerException();}}上面的类包含2个方法

java - 为什么没有为 Jersey Controller 检测到我的方面(使用自定义注释)?

我想在JerseyController上创建一个方面来测量执行服务需要多长时间。我正在反对我的切入点,因为它未被检测到并且我的方面从未启动。我尝试过使用很多切入点,例如:execution(@Monitor**.*(..))execution(public**(..))changetheorderof@Aspectand@ComponentAddedapointcutlikethis:@Pointcut("execution(@Monitor**.*(..))")publicvoidmonitorRequestTargets(){}@Around("monitorRequestTarg

java - 通过自定义注解注入(inject)常量

我的代码中有一堆常量,用于我系统的各种可调整属性。我将它们全部移动到中央.properties文件中。我当前的解决方案是使用一个Properties.java静态加载.properties文件并公开各种getter方法,如下所示:publicclassProperties{privatestaticfinalStringFILE_NAME="myfile.properties";privatestaticfinaljava.util.Propertiesprops;static{InputStreamin=Properties.class.getClassLoader().getRes