This is old fashioned JNDI and you have a couple of problems here.
Your web.xml
has correctly defined
<res-ref-name>jdbc/ConsipGfrDS</res-ref-name>
These resource references define names in the JNDI java:comp/env
namespace, otherwise known as the component environment namespace which is local to your web application. This means that the full JNDI name of your datasource in your web application is actually java:comp/env/jdbc/ConsipGfrDS
, so your lookup code should be:
@Bean
public DataSource dataSource() throws NamingException {
Context ctx = new InitialContext();
return (DataSource)ctx.lookup("java:comp/env/jdbc/ConsipGfrDS");
}
So far we have platform independent (i.e. application server) code. You have correctly pushed the platform dependent part into the weblogic.xml
file.
However this is where your second problem lies. The weblogic.xml
contains a small error. The weblogic console image that you provided showing the JDBC DataSource configuration says that the JNDI name is jdbc/ConsipGfrDS
. Therefore, update it as follows:
<?xml version="1.0" encoding="UTF-8" ?>
<weblogic-web-app
xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://xmlns.oracle.com/weblogic/weblogic-web-app http://http://www.oracle.com/technology/weblogic/weblogic-web-app/1.1/weblogic-web-app.xsd">
<resource-description>
<!-- match jndi name in weblogic -->
<jndi-name>jdbc/ConsipGfrDS</jndi-name>
<!-- match res-ref-name name in web.xml -->
<res-ref-name>jdbc/ConsipGfrDS</res-ref-name>
</resource-description>
</weblogic-web-app>
Have fun!