DatasourceRealm Tomcat 6 configuration: Name jdbc is not bound in this Context

StackOverflow https://stackoverflow.com/questions/16698870

  •  30-05-2022
  •  | 
  •  

Question

I'm configuring a DatasourceRealm in Tomcat 6 configuring everything in META-INF/context.xml. web.xml seems to be configured correctly since login prompt is showing up.

Can someone help?

context.xml

<Context >
    <Resource name="jdbc/auth" description="authentication" type="javax.sql.DataSource"
        auth="Container" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
        maxActive="25" maxIdle="10" maxWait="10000"
        url="jdbc:sqlserver://SQLSERVER;databaseName=db;integratedSecurity=true"
        validationQuery="select 1" />
    <Realm className="org.apache.catalina.realm.DataSourceRealm"
        dataSourceName="jdbc/auth" userTable="WebUsers" userNameCol="username"
        userCredCol="password" userRoleTable="WebUserRoles" roleNameCol="role" 
        localDataSource="true"/>
</Context>

Stack

javax.naming.NameNotFoundException: Name jdbc is not bound in this Context

Était-ce utile?

La solution

I figured out the issue. Under $CATALINA_BASE\conf\Catalina\localhost, there was another [App Name].xml file that was older (it did not have the localDatasource="true" flag) and did not have the same configuration I posted. I removed that file and redeployed my war. It worked after that.

Autres conseils

While doing the deployment we encountered the issue as seen below. We presumed at first it was an issue with setenv.sh and conpass file (this is where the properties files and passwords are consolidated), however, after redeploying each file one at a time we isolated the problem to MasterFile that was causing the issue. More specifically, the issue in itself was a false indicator because there was nothing actually wrong with coding or deployment in itself. The issue was thrown because we had backup MasterFile directories within the Tomcat webapps directory. In doing so, it created the following SEVERE error:

SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'datasource' defined in ServletContext resource [/WEB-INF/beans.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [jdbc/CRIDB] is not bound in this Context. Unable to find [jdbc].
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338).

The error was thrown was because we had multiple directories in place and when bringing up the server tomcat was trying to read each one. Once we removed the backup MasterFile directories the issue was resolved

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top