使用websphere 8.5.5.0和Spring配置数据源?

时间:2017-06-05 08:17:04

标签: java spring-mvc datasource websphere-8

我试图弄清楚使用websphere 8.5和spring连接的问题。我在本网站和其他网站上阅读了一些问题,但似乎没有任何效果。

在websphere中,我们必须将数据源的jndi名称设置为jdbc / connection0。

我尝试使用web.xml和弹簧配置文件在Web应用程序中设置连接。

<resource-ref >
    <description>connection0</description>
    <res-ref-name>connection0</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
    <mapped-name>connection0</mapped-name>   
</resource-ref> 

比在spring-datasource.xml中我们尝试引用连接:

        <property name="jndiName" value="jdbc/connection0"/>
        <property name="lookupOnStartup" value="false"/>
        <property name="cache" value="true"/>
        <property name="proxyInterface" value="javax.sql.DataSource"/>           
  </bean>

我还添加了文件ibm-web-bnd.xml来引用数据源(该文件位于web-inf目录下):

  

&LT; ?xml version =&#34; 1.0&#34;编码=&#34; UTF-8&#34;&GT;   &LT;网络BND      的xmlns =&#34; HTTP://websphere.ibm.com/xml/ns/javaee"      的xmlns:=的xsi&#34; HTTP://www.w3.org/2001/XMLSchema-instance"      xsi:schemaLocation =&#34; http://websphere.ibm.com/xml/ns/javaee> http://websphere.ibm.com/xml/ns/javaee/ibm-web-bnd_1_0.xsd&#34;      版本=&#34; 1.0&#34; &GT;

     

     

  

我们生成一个EAR文件,并成功部署在应用程序服务器上。 但是当我们尝试访问数据库时,我们收到一个错误,这就是stacktrace:

  

[05/06/17 9.59.33:514 CEST] 0000006f SystemOut O it.XXXX.sicurezza.db.DbHelper - &gt; openJndiConnection:找不到initCtx.lookup(&#34; java:comp / env / url / connection0&#34;)。坟墓!!   [05/06/17 9.59.33:515 CEST] 0000006f SystemOut O 05-06-2017 09:59:33错误[WebContainer:1] it.XXXX.sicurezza.taglib.allow.AllowTag - NamingManager.getURLContext找不到这个方案的工厂:java   javax.naming.ConfigurationException:NamingManager.getURLContext无法找到此方案的工厂:java     在com.ibm.ws.naming.util.Helpers.checkForUrlContext(Helpers.java:1631)     在com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:160)     在com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:179)     在org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:161)     在javax.naming.InitialContext.lookup(InitialContext.java:423)     at it.XXXX.sicurezza.db.DbHelper.openJndiConnection(DbHelper.java:78)     at it.XXXX.sicurezza.db.DbHelper.openConnection(DbHelper.java:53)     at it.XXXX.sicurezza.db.DaoManager.isInternalSecurityEnabled(DaoManager.java:108)     at it.XXXX.sicurezza.manager.AbilitazioniManagerFactory.getAbilitazioniManager(AbilitazioniManagerFactory.java:29)     at it.XXXX.sicurezza.taglib.allow.AllowTag.doStartTag(AllowTag.java:116)     at com.ibm._jsp._editOrdineForm._jspx_meth_allow_allow_8(_editOrdineForm.java:7626)     at com.ibm._jsp._editOrdineForm._jspx_meth_c_if_39(_editOrdineForm.java:7668)     at com.ibm._jsp._editOrdineForm._jspService(_editOrdineForm.java:658)     在com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:99)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:668)     在com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1227)     在com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:776)     在com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:458)     在com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)     at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:122)     at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:216)     在com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:136)     在com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:79)     在com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:928)     在com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1025)     在com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:1385)     在com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.include(WebAppRequestDispatcher.java:549)     在org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:1045)     at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:527)     在org.apache.struts.tiles.TilesUtilImpl.doInclude(TilesUtilImpl.java:99)     在org.apache.struts.tiles.TilesUtil.doInclude(TilesUtil.java:135)     在org.apache.struts.taglib.tiles.InsertTag.doInclude(InsertTag.java:760)     at org.apache.struts.taglib.tiles.InsertTag $ InsertHandler.doEndTag(InsertTag.java:892)     在org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:462)     at com.ibm._jsp._layout._jspx_meth_tiles_insert_3(_layout.java:451)     在com.ibm._jsp._layout._jspService(_layout.java:201)     在com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:99)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:668)     在com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1227)     在com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:776)     在com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:458)     在com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)     at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:122)     at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:216)     在com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:136)     在com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:79)     在com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:928)     在com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1025)     在com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:1385)     在com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:194)     在org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:240)     在org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:258)     在org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1174)     在org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:901)     在org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)     在org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)     在org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:575)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:668)     在com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1227)     在com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:776)     在com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:458)     在com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)     在com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:136)     在com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:79)     在com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:928)     在com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1025)     在com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:1385)     在com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:194)     在org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:240)     在org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:258)     在org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1174)     在org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:901)     在org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)     在org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)     在org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:575)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:668)     在com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1227)     在com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:776)     在com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:458)     在com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)     在com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:136)     在com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:97)     在org.acegisecurity.util.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:265)     at it.XXXX.oppe0.allow.filter.AllowFilter.doFilter(AllowFilter.java:125)     在org.acegisecurity.util.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:275)     at org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:107)     at org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:72)     在org.acegisecurity.util.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:275)     at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:124)     在org.acegisecurity.util.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:275)     在org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125)     在org.acegisecurity.util.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:275)     at org.acegisecurity.wrapper.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:81)     在org.acegisecurity.util.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:275)     at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:271)     在org.acegisecurity.util.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:275)     at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:271)     在org.acegisecurity.util.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:275)     在org.acegisecurity.ui.logout.LogoutFilter.doFilter(LogoutFilter.java:110)     在org.acegisecurity.util.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:275)     at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:249)     在org.acegisecurity.util.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:275)     at it.XXXX.oppe0.acegi.SessionExpirationFilter.doFilter(SessionExpirationFilter.java:76)     在org.acegisecurity.util.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:275)     在org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:149)     在org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)     在com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)     在com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)     at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)     在com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)     在com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)     在com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:928)     在com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1025)     在com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3761)     在com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)     在com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:976)     在com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)     在com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:200)     在com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:459)     在com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:526)     在com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:312)     在com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:88)     在com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)     在com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)     at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)     在com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)     在com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)     在com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)     在com.ibm.io.async.ResultHandler $ 2.run(ResultHandler.java:905)     在com.ibm.ws.util.ThreadPool $ Worker.run(ThreadPool.java:1862)

有关设置的任何建议吗?

1 个答案:

答案 0 :(得分:0)

如果您有一个想要查找数据源的应用程序

java:comp/env/url/connection0

您的服务器配置定义了JNDI名称为

的数据源
jdbc/connection0

然后web.xml中的资源引用应为

<resource-ref >
    <description>connection0</description>
    <res-ref-name>url/connection0</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref> 

您可以在绑定文件(ibm-web-bnd.xml)中定义映射,如下所示:

<resource-ref name="url/connection0" binding-name="jdbc/connection0">
</resource-ref>