简体   繁体   中英

Impossible to deploy on Weblogic

I tried to apply all the solutions in these questions:

Tomcat vs Weblogic JNDI Lookup

javax.naming.NameNotFoundException:while trying to lookup jdbc

but they didn't solve my problem. I'm using Maven and WebLogic.

In my web.xml I used the tag 'res-ref-name'.

Thanks a lot!

You have registered your data source withh the name " jndi /ConsipGfrDS", but looking up with " jdbc /ConsipGfrDS". Use one (no matter what, but the same) name in both cases.

I'd suggest that you use in JNDI the name " jdbc /ConsipGfrDS", because it will be easier to sort objects out if you have many objects in JNDI.

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 (ie 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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM