无法在Weblogic上部署

问题描述 投票:1回答:2

我试图在这些问题中应用所有解决方案:

Tomcat vs Weblogic JNDI Lookup

Unable to access weblogic datasource from java with prefix jdbc/

NameNotFoundException: While trying to lookup 'jdbc' only when publishing from Eclipse Kepler but not Indigo

javax.naming.NameNotFoundException: While trying to lookup 'jdbc.teradata' didn't find subcontext 'jdbc'. Resolved ''; remaining name 'jdbc/teradata'

javax.naming.NameNotFoundException:while trying to lookup jdbc

Weblogic javax.naming.NameNotFoundException while running application

但是他们没有解决我的问题。我正在使用Spring MVC,Maven(多模块项目)和WebLogic。这是我的包结构:

enter image description here

这是我的web.xml:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_4_0.xsd"
      version="4.0">
      <resource-ref>
    <description>ConsipDataSource</description>
    <res-ref-name>jdbc/ConsipGfrDS</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>
</web-app>

这是我的weblogic.xml:

<?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>
    <jndi-name>ConsipGfrDS</jndi-name>
    <res-ref-name>jdbc/ConsipGfrDS</res-ref-name>
</resource-description>

</weblogic-web-app>

这是我的带有Jdbc数据源的weblogic控制台:

enter image description here

我的配置类的bean方法是:

@Bean
    public DataSource dataSource() throws NamingException {
        Context ctx = new InitialContext();
        return (DataSource)ctx.lookup("jdbc/ConsipGfrDS");

    }

我有这个例外:

[ERROR] Target state: deploy failed on Server AdminServer
[ERROR] javax.naming.NameNotFoundException: Unable to resolve 'jdbc.ConsipGfrDS'. Resolved 'jdbc'; remaining name 'ConsipGfrDS'

您能帮我解决这个错误吗?

非常感谢!

java maven spring-mvc deployment weblogic
2个回答
1
投票
jndi / ConsipGfrDS”注册了数据源,但是使用“

jdbc / ConsipGfrDS”进行了查找。在两种情况下都使用一个(无论什么名称,但要相同)名称。

我建议您在JNDI中使用名称“ jdbc / ConsipGfrDS”,因为如果JNDI中有许多对象,则将更容易将对象分类。

0
投票
您的web.xml已正确定义

<res-ref-name>jdbc/ConsipGfrDS</res-ref-name>

这些资源引用在JNDI java:comp/env命名空间中定义名称,否则称为Web应用程序本地的组件环境命名空间。这意味着您的Web应用程序中数据源的完整JNDI名称实际上是java:comp/env/jdbc/ConsipGfrDS,因此您的查找代码应为:

@Bean
public DataSource dataSource() throws NamingException {
    Context ctx = new InitialContext();
    return (DataSource)ctx.lookup("java:comp/env/jdbc/ConsipGfrDS");
}

到目前为止,我们已经有了平台

independent(即应用服务器)代码。您已将平台

dependent部件正确推入weblogic.xml文件。

但是这是您的第二个问题所在。 weblogic.xml包含一个小错误。您提供的显示JDBC DataSource配置的weblogic控制台映像显示JNDI名称为jdbc/ConsipGfrDS。因此,如下更新:<?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>

玩得开心!

© www.soinside.com 2019 - 2024. All rights reserved.