Hi!
I'm pretty sure your dataSource is being injected, otherwise you'd
receive a different error and not an NPE.
This looks wrong to me:
binder.bind(DataSource.class,
AppModule.getJndiDataSource().getClass()).withId("blog.dataSource");
Specifically the:
AppModule.getJndiDataSource().getClass()
Do you not know what the class is at compile time? Rather than
binding, you may want a use Builder method.
Also, the binding gives an ID of "blog.dataSource" but you're
injecting "myDataSource"...?
As an aside, I usually inject services in my Module with this:
public void contributeWebSecurityManager(
final Configuration<Realm> configuration
@Local DataSource dataSource) {
...
}
No need for @InjectService.
The @Local tells T5-IoC to look for a service defined in *that* module
class. Because DataSource is a popular interface, it could be defined
in other modules. The annotation helps to dis-ambiguate between them.
Steve.
On 20 June 2012 20:47, cablepuff <[email protected]> wrote:
> Hi i have the following problem. I have set the following code.
>
> public void contributeWebSecurityManager(
> final Configuration<Realm> configuration
> //, @InjectService("myDataSource")final DataSource
> dataSource
> ) {
> final JdbcRealm realm = new JdbcSaltedRealm();
> realm.setDataSource(getJndiDataSource());
> // realm.setDataSource(dataSource); -- does not work
> realm.setAuthenticationQuery(AppModule.AUTHENTICATION_QUERY);
> realm.setUserRolesQuery(AppModule.USER_ROLES_QUERY);
> realm.setPermissionsQuery(AppModule.PERMISSION_QUERY);
> realm.setPermissionsLookupEnabled(true);
> realm.setCredentialsMatcher(this.credentialsMatcher);
> configuration.add(realm);
> }
>
> In the same AppModule class I have this
>
> public static void bind(final ServiceBinder binder) {
> binder.bind(DataSource.class,
> AppModule.getJndiDataSource().getClass())
> .withId("blog.dataSource");
> }
>
> When i run my app it seems the datasource is not injected. How am I able to
> inject the datasource binded into ContributeWebSecurityManager.
>
> This is error i am getting when using service injection instead of just
> manually getting the datasource.
>
> NFO: Cannot create JDBC driver of class '' for connect URL 'null'
> java.lang.NullPointerException
> at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:524)
> at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:493)
> at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
> at java.sql.DriverManager.getDriver(DriverManager.java:273)
> at
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
> at
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
> at
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
> at $DataSource_210503fddf1.getConnection(Unknown Source)
> at
> org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
> at
> org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
> at
> org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:573)
> at
> org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:637)
> at
> org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:666)
> at
> org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:674)
> at
> org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:729)
> at
> org.apache.shiro.realm.JdbcSaltedRealm.getPasswordForUser(JdbcSaltedRealm.java:242)
> at
> org.apache.shiro.realm.JdbcSaltedRealm.doGetAuthenticationInfo(JdbcSaltedRealm.java:170)
> at
> org.apache.shiro.realm.JdbcSaltedRealm.doGetAuthenticationInfo(JdbcSaltedRealm.java:61)
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/AppModule-using-injected-service-in-ContributeWebSecurityManager-tp5713989.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]