How To Use Annotations - Limitations And Possibilities

Jun 20, 2015

I was just programming, when I discovered that you can create custom annotations. So I was wondering: what can I use these for? I a m also curious about what the limitations and possibilities are and what to put in the program.

View Replies


ADVERTISEMENT

Servlets :: Possible To Use Annotations?

Aug 10, 2014

Is it permitted or possible to use annotations on classic servlets?

E.g.:

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

[Code] ....

I tried to visit my webapp with /appinfo appended after the context url but I get a 404 and I see no errors in the GlassFish4 log.

My project is using JSF 2.x with the viewservlet mapped on *.xhtml and it is using Spring Beans as well (using the Spring Context Loader), mapped to /rest/*. Do I need to map something else?

I can only get this servlet working without annotations but only using the old web.xml way.

I don't know what I need to do to get my servlet working with annotations.

View Replies View Related

Custom Annotations And Spring MVC

Jan 23, 2015

I'm running spring MVC on a tomcat server and am fiddling around with beans and annotations.

First, I have a class Library, with a registerBook(<T> Book) method. This one is annotated with @BookRegistry

Next, I have an Interface Book, which basically is a bean with some custom methods.

I will create different types of books that implement my Book interface and annotate them with @LibraryBook

Now, I want to have spring to check for all beans with @LibraryBook at server startup and run registerBook for each and every one.

How do I accomplish this?

View Replies View Related

EJB / EE :: Bean Annotations And Unit Testing?

Mar 6, 2014

I have a bean that represents data been collected from a form on a jsp page. Currently I would like to validate my fields and write some test cases for them. As you can see from my test case example I test a string in the hope that it fails because it contains only one letter. My problem is my unit test is passing. The reason this is from what I can tell is that at runtime it fails when I try to persist my object using my entity manager. During my unit test I just I don’t call my entity manager I just try and set the field.

What I thought would happen was that when I use my bean fields set method the annotations would be checked and fail at that point. Hence why I expected my unit test in this case to fail.

What I would like to know is

1.Are annotations specifically designed to validate when I persist my object and am I using them incorrectly at this point?

2.Is this the best method to use to validate fields, is there a better way, should I write my own code to validate for me when I set my value?

a. Should I throw an exception from the set method of each bean field?

Unit Test:

@Test
public void testName(){
Human h=new Human();
try {
h.setFname("a");
} catch (Exception e) {
// TODO Auto-generated catch block
fail("failed");
e.printStackTrace();

[code]....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved