You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by MMA_EDFX <ma...@edifixio.com> on 2016/11/18 05:35:21 UTC

Getting javax.naming.NameNotFoundException: Name [myJDBC_dataSource] is not bound in this Context. Unable to find [myJDBC_dataSource]

Hello,

I am getting the below exception while doing JNDI lookup for the Datasource
defined in tomee.xml

javax.naming.NameNotFoundException: Name [myJDBC_dataSource] is not bound in
this Context. Unable to find [myJDBC_dataSource].
        at org.apache.naming.NamingContext.lookup(NamingContext.java:817)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:174)
        at
org.apache.naming.SelectorContext.lookup(SelectorContext.java:163)
        at javax.naming.InitialContext.lookup(InitialContext.java:417)
        at
com.mycompany.jms.service.MessageListnerServiceImpl.getConnection(MessageListnerServiceImpl.java:53)

I have defined Datasource in tomee.xml as

<Resource id="myJDBC_dataSource" type="DataSource">
		JdbcDriver   org.postgresql.Driver
		JdbcUrl  jdbc:postgresql://localhost:5432/MyApp
		UserName     myUser
		Password     myPassword
		defaultAutoCommit = false
		jtaManaged = true
		maxActive = 20
		maxIdle = 5
		maxWaitTime = 10000ms
		minEvictableIdleTime = 30min
		minIdle = 0
		numTestsPerEvictionRun = 3
		testOnBorrow = true
		testOnReturn = true
		testWhileIdle = true
		timeBetweenEvictionRuns = 10min
		validationQuery = select 1
		LogSql = false
	</Resource>

Here is my MessageListener class 

@MessageDriven(
		name = "MyJMSQueue",
		mappedName = "MyJMSQueue",
				messageListenerInterface=MessageListener.class,
				activationConfig = {@ActivationConfigProperty(propertyName =
"destinationType",propertyValue = "javax.jms.Queue"),
									@ActivationConfigProperty(propertyName =
"acknowledgeMode",propertyValue = "Auto-acknowledge"),
									@ActivationConfigProperty(propertyName =
"maxSessions",propertyValue = "1")})
				
public class MessageListnerServiceImpl implements MessageListener {

	@Override
	public void onMessage(Message message) {
		ObjectMessage objectMessage = (ObjectMessage) message;
        String messages = null;
        try {
        	Connection conn = getConnection("myJDBC_dataSource");
    		System.out.println("########################### "+conn);
        	messages = (String) objectMessage.getObject();
        	System.out.println("MessageListnerServiceImpl messages " +
messages);
        	
        } catch (JMSException e) {
            e.printStackTrace();
        }
        catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static Connection getConnection(String datasourceName) throws
Exception{
        DataSource dataSource=null;
        try {
            dataSource = (DataSource)new
InitialContext().lookup(datasourceName);    
        }
        catch (NamingException e){
            throw new Exception("getConnection - NamingException when lookup
dataSource '"+datasourceName+"'",e);
        }
        try {
            Connection myConnection = dataSource.getConnection();
            System.out.println("getConnection - DatasourceConnection
connection '"+myConnection+"' is retrieved from DataSource
'"+datasourceName+"'");
            return myConnection;
        }
        catch (SQLException e){
            throw new Exception("getConnection - SQLException when try to
getConnection from dataSource '"+datasourceName+"'",e);
        }    
    }
}

I have tried to look up with java:comp/env/myJDBC_dataSource. But no
success.

How do I solve the issue?



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Getting-javax-naming-NameNotFoundException-Name-myJDBC-dataSource-is-not-bound-in-this-Context-Unabl-tp4680583.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Getting javax.naming.NameNotFoundException: Name [myJDBC_dataSource] is not bound in this Context. Unable to find [myJDBC_dataSource]

Posted by MMA_EDFX <ma...@edifixio.com>.
Used openejb:Resource/myJDBC_dataSource for JNDI lookup and it is working
fine.



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Getting-javax-naming-NameNotFoundException-Name-myJDBC-dataSource-is-not-bound-in-this-Context-Unabl-tp4680583p4680588.html
Sent from the TomEE Users mailing list archive at Nabble.com.