Java Reference
In-Depth Information
return id;
}
public void setId(long id) {
this.id = id;
}
}
The resource injection and security annotations are defined in the Common
Annotations for the Java Platform specification, and are in the
javax.annotation
and
javax.annotation.security
packages. For example, the
@Resource
injection
may be used to inject a
javax.sql.DataSource
resource. First, configure a
data source in a Java EE container. Subsequently, inject a data source handle by
annotating a declaration for a variable of type javax.sql.DataSource with the
@
Resource
annotation.
@Resource
private javax.sql.DataSource mysqlDS;
public getCatalogEntry(){
Connection conn = mysqlDS.getConnection();
}
Data source injection using the
@Resource
annotation precludes the requirement
for JNDI lookup using an
InitialContext
object. The security annotations are
presented in the following table.
Annotation
Description
DeclareRoles
Declares references to security roles
RolesAllowed
Declares the methods that are allowed to invoke the methods of the
entity bean
PermitAll
Specifies that all security roles are allowed to invoke the specified
methods.
DenyAll
Specifies that no security roles are allowed to invoke the specified
methods.
RunAs
Specify a security role as the bean's run-as property.
Search WWH ::
Custom Search