OpenLiberty / open-liberty

Open Liberty is a highly composable, fast to start, dynamic application server runtime environment
https://openliberty.io
Eclipse Public License 2.0
1.15k stars 587 forks source link

Configuring authentication data and aliases with authData and a resource reference documentation has a bug in first example #20658

Open jmstephensgit opened 2 years ago

jmstephensgit commented 2 years ago

In the documentation, https://www.ibm.com/docs/en/was-liberty/base?topic=applications-configuring-authentication-aliases-liberty#twlp_sec_jca__adeappbind

  1. Add a Resource annotation to your application to enable the application server to inject the resource reference or add the resource to your application deployment descriptor.

@Resource (lookup="jdbc/mydbresource") DataSource mydbresource;

should be changed to

Add a Resource annotation to your application to enable the application server to inject the resource reference or add the resource to your application deployment descriptor.

@Resource (name="jdbc/mydbresource") DataSource mydbresource;

In addition, the first example should be to the last example. Add a code example using the resource created.

Connection c = mydbresource.getConnection();

njr-11 commented 2 years ago

To make the example as clear as possible, change it to:

@Resource(name = "java:comp/env/jdbc/mydbresourceRef",  lookup="jdbc/mydbresource")
DataSource mydbresource;

and

<resource-ref name="java:comp/env/jdbc/mydbresourceRef">
  <authentication-alias name="auth1"/>
</resource-ref>

By avoiding using the same name for 2 different things, that will make it more clear to the reader which each pertains to.