|
My plan was to add mybatis and mybatis-guice to the app described here
http://blog.curran.in/2010/02/creating-restful-service-with-jersey.html and use that as a starting point for my own app. The injection of a mapper into a JAX-RS resource class constructor works fine. I can even break into the debugger and successfully use the mapper within the constructor. _But_ as soon as I declare the mapper as a field in the resource class, I get this strange error: com.google.inject.CreationException: Guice creation errors: 1) Error in custom provider, java.lang.NullPointerException while locating org.mybatis.guice.datasource.builtin.UnpooledDataSourceProvider while locating javax.sql.DataSource for parameter 2 at org.mybatis.guice.environment.EnvironmentProvider.<init>(EnvironmentProvider.java:51) while locating org.mybatis.guice.environment.EnvironmentProvider while locating org.apache.ibatis.mapping.Environment for parameter 0 at org.mybatis.guice.configuration.ConfigurationProvider.<init>(ConfigurationProvider.java:52) while locating org.mybatis.guice.configuration.ConfigurationProvider while locating org.apache.ibatis.session.Configuration for parameter 0 at org.mybatis.guice.SqlSessionFactoryProvider.<init>(SqlSessionFactoryProvider.java:45) while locating org.mybatis.guice.SqlSessionFactoryProvider while locating org.apache.ibatis.session.SqlSessionFactory for parameter 0 at org.mybatis.guice.SqlSessionManagerProvider.<init>(SqlSessionManagerProvider.java:35) while locating org.mybatis.guice.SqlSessionManagerProvider while locating org.apache.ibatis.session.SqlSessionManager for field at org.mybatis.guice.MapperProvider.sqlSessionManager(MapperProvider.java:42) at org.mybatis.guice.MyBatisModule.bindMapperProvider(MyBatisModule.java:270) 1 error at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:354) at com.google.inject.InjectorBuilder.injectDynamically(InjectorBuilder.java:173) at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:113) at com.google.inject.Guice.createInjector(Guice.java:92) at com.google.inject.Guice.createInjector(Guice.java:69) at com.google.inject.Guice.createInjector(Guice.java:59) at de.fortisit.common.guice.GuiceConfig.getInjector(GuiceConfig.java:32) at com.google.inject.servlet.GuiceServletContextListener.contextInitialized(GuiceServletContextListener.java:43) Here is how I configure guice: public class GuiceConfig extends GuiceServletContextListener { protected Injector getInjector() { //Class<? extends Provider<DataSource>> dataSourceProviderClass = C3p0DataSourceProvider.class; Class<? extends Provider<DataSource>> dataSourceProviderClass = UnpooledDataSourceProvider.class; Class<? extends Provider<TransactionFactory>> txFactoryProviderClass = JdbcTransactionFactoryProvider.class; final Map<String, String> params = new HashMap<String, String>(); params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "de.fortisit.weblog.resources"); Injector injector = Guice.createInjector( new Module() { public void configure(Binder binder) { binder.bindConstant().annotatedWith(Names.named("mybatis.environment.id")).to("development"); binder.bindConstant().annotatedWith(Names.named("JDBC.driver")).to("com.mysql.jdbc.Driver"); binder.bindConstant().annotatedWith(Names.named("JDBC.url")).to("jdbc:mysql://localhost/weblog_dev"); binder.bindConstant().annotatedWith(Names.named("JDBC.username")).to("weblog"); binder.bindConstant().annotatedWith(Names.named("JDBC.password")).to("weblog"); } }, new MyBatisModule(dataSourceProviderClass, txFactoryProviderClass) .addMapperClasses(TaskMapper.class), new Jsr250Module(), new ServletModule() { @Override protected void configureServlets() { serve("/*").with(GuiceContainer.class, params); } } ); SqlSessionFactory sessionFactory = injector.getInstance(SqlSessionFactory.class); System.out.println(sessionFactory); return injector; } } And this is the resource class: @Path("hello") public class HelloResource { private ItemResource item; private TaskMapper taskMapper; // <<<---- This causes the error @Inject public HelloResource(ItemResource item, TaskMapper taskMapper) { this.item = item; //this.taskMapper = taskMapper; } @GET public String index() { //List<TaskDto> tasks = taskMapper.selectAll(); System.out.println("HelloResource.index() invoked..."); return "Hello World"; } I am getting desperate. Any help much appreciated! |
|
Hi Stephen,
I'm studying the case you submitted, just give me the time to provide you a valid help! Have a nice day, Simo http://people.apache.org/~simonetripodi/ http://www.99soft.org/ On Mon, Sep 6, 2010 at 1:45 AM, Stephen Friedrich <[hidden email]> wrote: > My plan was to add mybatis and mybatis-guice to the app described here > http://blog.curran.in/2010/02/creating-restful-service-with-jersey.html > and use that as a starting point for my own app. > > The injection of a mapper into a JAX-RS resource class constructor works fine. > I can even break into the debugger and successfully use the mapper within the constructor. > _But_ as soon as I declare the mapper as a field in the resource class, I get this strange error: > > com.google.inject.CreationException: Guice creation errors: > > 1) Error in custom provider, java.lang.NullPointerException > while locating org.mybatis.guice.datasource.builtin.UnpooledDataSourceProvider > while locating javax.sql.DataSource > for parameter 2 at org.mybatis.guice.environment.EnvironmentProvider.<init>(EnvironmentProvider.java:51) > while locating org.mybatis.guice.environment.EnvironmentProvider > while locating org.apache.ibatis.mapping.Environment > for parameter 0 at org.mybatis.guice.configuration.ConfigurationProvider.<init>(ConfigurationProvider.java:52) > while locating org.mybatis.guice.configuration.ConfigurationProvider > while locating org.apache.ibatis.session.Configuration > for parameter 0 at org.mybatis.guice.SqlSessionFactoryProvider.<init>(SqlSessionFactoryProvider.java:45) > while locating org.mybatis.guice.SqlSessionFactoryProvider > while locating org.apache.ibatis.session.SqlSessionFactory > for parameter 0 at org.mybatis.guice.SqlSessionManagerProvider.<init>(SqlSessionManagerProvider.java:35) > while locating org.mybatis.guice.SqlSessionManagerProvider > while locating org.apache.ibatis.session.SqlSessionManager > for field at org.mybatis.guice.MapperProvider.sqlSessionManager(MapperProvider.java:42) > at org.mybatis.guice.MyBatisModule.bindMapperProvider(MyBatisModule.java:270) > > 1 error > at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:354) > at com.google.inject.InjectorBuilder.injectDynamically(InjectorBuilder.java:173) > at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:113) > at com.google.inject.Guice.createInjector(Guice.java:92) > at com.google.inject.Guice.createInjector(Guice.java:69) > at com.google.inject.Guice.createInjector(Guice.java:59) > at de.fortisit.common.guice.GuiceConfig.getInjector(GuiceConfig.java:32) > at com.google.inject.servlet.GuiceServletContextListener.contextInitialized(GuiceServletContextListener.java:43) > > Here is how I configure guice: > public class GuiceConfig extends GuiceServletContextListener { > protected Injector getInjector() { > > //Class<? extends Provider<DataSource>> dataSourceProviderClass = C3p0DataSourceProvider.class; > Class<? extends Provider<DataSource>> dataSourceProviderClass = UnpooledDataSourceProvider.class; > > Class<? extends Provider<TransactionFactory>> txFactoryProviderClass = JdbcTransactionFactoryProvider.class; > > final Map<String, String> params = new HashMap<String, String>(); > params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "de.fortisit.weblog.resources"); > > Injector injector = Guice.createInjector( > new Module() { > public void configure(Binder binder) { > binder.bindConstant().annotatedWith(Names.named("mybatis.environment.id")).to("development"); > binder.bindConstant().annotatedWith(Names.named("JDBC.driver")).to("com.mysql.jdbc.Driver"); > binder.bindConstant().annotatedWith(Names.named("JDBC.url")).to("jdbc:mysql://localhost/weblog_dev"); > binder.bindConstant().annotatedWith(Names.named("JDBC.username")).to("weblog"); > binder.bindConstant().annotatedWith(Names.named("JDBC.password")).to("weblog"); > } > }, > new MyBatisModule(dataSourceProviderClass, txFactoryProviderClass) > .addMapperClasses(TaskMapper.class), > new Jsr250Module(), > new ServletModule() { > @Override > protected void configureServlets() { > serve("/*").with(GuiceContainer.class, params); > } > } > ); > > SqlSessionFactory sessionFactory = injector.getInstance(SqlSessionFactory.class); > System.out.println(sessionFactory); > > return injector; > } > } > > And this is the resource class: > @Path("hello") > public class HelloResource { > private ItemResource item; > > private TaskMapper taskMapper; // <<<---- This causes the error > > @Inject > public HelloResource(ItemResource item, TaskMapper taskMapper) { > this.item = item; > //this.taskMapper = taskMapper; > } > > @GET > public String index() { > //List<TaskDto> tasks = taskMapper.selectAll(); > System.out.println("HelloResource.index() invoked..."); > return "Hello World"; > } > > I am getting desperate. Any help much appreciated! > |
|
A trivial question: is this an Open or Closed source project? If open,
I'd more then glad to check it out to help you. Thanks in advance, Simo http://people.apache.org/~simonetripodi/ http://www.99soft.org/ On Mon, Sep 6, 2010 at 7:50 AM, Simone Tripodi <[hidden email]> wrote: > Hi Stephen, > I'm studying the case you submitted, just give me the time to provide > you a valid help! > Have a nice day, > Simo > > http://people.apache.org/~simonetripodi/ > http://www.99soft.org/ > > > > On Mon, Sep 6, 2010 at 1:45 AM, Stephen Friedrich > <[hidden email]> wrote: >> My plan was to add mybatis and mybatis-guice to the app described here >> http://blog.curran.in/2010/02/creating-restful-service-with-jersey.html >> and use that as a starting point for my own app. >> >> The injection of a mapper into a JAX-RS resource class constructor works fine. >> I can even break into the debugger and successfully use the mapper within the constructor. >> _But_ as soon as I declare the mapper as a field in the resource class, I get this strange error: >> >> com.google.inject.CreationException: Guice creation errors: >> >> 1) Error in custom provider, java.lang.NullPointerException >> while locating org.mybatis.guice.datasource.builtin.UnpooledDataSourceProvider >> while locating javax.sql.DataSource >> for parameter 2 at org.mybatis.guice.environment.EnvironmentProvider.<init>(EnvironmentProvider.java:51) >> while locating org.mybatis.guice.environment.EnvironmentProvider >> while locating org.apache.ibatis.mapping.Environment >> for parameter 0 at org.mybatis.guice.configuration.ConfigurationProvider.<init>(ConfigurationProvider.java:52) >> while locating org.mybatis.guice.configuration.ConfigurationProvider >> while locating org.apache.ibatis.session.Configuration >> for parameter 0 at org.mybatis.guice.SqlSessionFactoryProvider.<init>(SqlSessionFactoryProvider.java:45) >> while locating org.mybatis.guice.SqlSessionFactoryProvider >> while locating org.apache.ibatis.session.SqlSessionFactory >> for parameter 0 at org.mybatis.guice.SqlSessionManagerProvider.<init>(SqlSessionManagerProvider.java:35) >> while locating org.mybatis.guice.SqlSessionManagerProvider >> while locating org.apache.ibatis.session.SqlSessionManager >> for field at org.mybatis.guice.MapperProvider.sqlSessionManager(MapperProvider.java:42) >> at org.mybatis.guice.MyBatisModule.bindMapperProvider(MyBatisModule.java:270) >> >> 1 error >> at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:354) >> at com.google.inject.InjectorBuilder.injectDynamically(InjectorBuilder.java:173) >> at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:113) >> at com.google.inject.Guice.createInjector(Guice.java:92) >> at com.google.inject.Guice.createInjector(Guice.java:69) >> at com.google.inject.Guice.createInjector(Guice.java:59) >> at de.fortisit.common.guice.GuiceConfig.getInjector(GuiceConfig.java:32) >> at com.google.inject.servlet.GuiceServletContextListener.contextInitialized(GuiceServletContextListener.java:43) >> >> Here is how I configure guice: >> public class GuiceConfig extends GuiceServletContextListener { >> protected Injector getInjector() { >> >> //Class<? extends Provider<DataSource>> dataSourceProviderClass = C3p0DataSourceProvider.class; >> Class<? extends Provider<DataSource>> dataSourceProviderClass = UnpooledDataSourceProvider.class; >> >> Class<? extends Provider<TransactionFactory>> txFactoryProviderClass = JdbcTransactionFactoryProvider.class; >> >> final Map<String, String> params = new HashMap<String, String>(); >> params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "de.fortisit.weblog.resources"); >> >> Injector injector = Guice.createInjector( >> new Module() { >> public void configure(Binder binder) { >> binder.bindConstant().annotatedWith(Names.named("mybatis.environment.id")).to("development"); >> binder.bindConstant().annotatedWith(Names.named("JDBC.driver")).to("com.mysql.jdbc.Driver"); >> binder.bindConstant().annotatedWith(Names.named("JDBC.url")).to("jdbc:mysql://localhost/weblog_dev"); >> binder.bindConstant().annotatedWith(Names.named("JDBC.username")).to("weblog"); >> binder.bindConstant().annotatedWith(Names.named("JDBC.password")).to("weblog"); >> } >> }, >> new MyBatisModule(dataSourceProviderClass, txFactoryProviderClass) >> .addMapperClasses(TaskMapper.class), >> new Jsr250Module(), >> new ServletModule() { >> @Override >> protected void configureServlets() { >> serve("/*").with(GuiceContainer.class, params); >> } >> } >> ); >> >> SqlSessionFactory sessionFactory = injector.getInstance(SqlSessionFactory.class); >> System.out.println(sessionFactory); >> >> return injector; >> } >> } >> >> And this is the resource class: >> @Path("hello") >> public class HelloResource { >> private ItemResource item; >> >> private TaskMapper taskMapper; // <<<---- This causes the error >> >> @Inject >> public HelloResource(ItemResource item, TaskMapper taskMapper) { >> this.item = item; >> //this.taskMapper = taskMapper; >> } >> >> @GET >> public String index() { >> //List<TaskDto> tasks = taskMapper.selectAll(); >> System.out.println("HelloResource.index() invoked..."); >> return "Hello World"; >> } >> >> I am getting desperate. Any help much appreciated! >> > |
|
Hi again Stephen,
can you check in you're classpath there's no MyBatis 3.0.1 and only 3.0.2? The Mappers auto-injection works with the 3.0.2 only, that's a lack in the documentation. Please let me know, alles gute! Simo http://people.apache.org/~simonetripodi/ http://www.99soft.org/ On Mon, Sep 6, 2010 at 8:13 AM, Simone Tripodi <[hidden email]> wrote: > A trivial question: is this an Open or Closed source project? If open, > I'd more then glad to check it out to help you. > Thanks in advance, > Simo > > http://people.apache.org/~simonetripodi/ > http://www.99soft.org/ > > > > On Mon, Sep 6, 2010 at 7:50 AM, Simone Tripodi <[hidden email]> wrote: >> Hi Stephen, >> I'm studying the case you submitted, just give me the time to provide >> you a valid help! >> Have a nice day, >> Simo >> >> http://people.apache.org/~simonetripodi/ >> http://www.99soft.org/ >> >> >> >> On Mon, Sep 6, 2010 at 1:45 AM, Stephen Friedrich >> <[hidden email]> wrote: >>> My plan was to add mybatis and mybatis-guice to the app described here >>> http://blog.curran.in/2010/02/creating-restful-service-with-jersey.html >>> and use that as a starting point for my own app. >>> >>> The injection of a mapper into a JAX-RS resource class constructor works fine. >>> I can even break into the debugger and successfully use the mapper within the constructor. >>> _But_ as soon as I declare the mapper as a field in the resource class, I get this strange error: >>> >>> com.google.inject.CreationException: Guice creation errors: >>> >>> 1) Error in custom provider, java.lang.NullPointerException >>> while locating org.mybatis.guice.datasource.builtin.UnpooledDataSourceProvider >>> while locating javax.sql.DataSource >>> for parameter 2 at org.mybatis.guice.environment.EnvironmentProvider.<init>(EnvironmentProvider.java:51) >>> while locating org.mybatis.guice.environment.EnvironmentProvider >>> while locating org.apache.ibatis.mapping.Environment >>> for parameter 0 at org.mybatis.guice.configuration.ConfigurationProvider.<init>(ConfigurationProvider.java:52) >>> while locating org.mybatis.guice.configuration.ConfigurationProvider >>> while locating org.apache.ibatis.session.Configuration >>> for parameter 0 at org.mybatis.guice.SqlSessionFactoryProvider.<init>(SqlSessionFactoryProvider.java:45) >>> while locating org.mybatis.guice.SqlSessionFactoryProvider >>> while locating org.apache.ibatis.session.SqlSessionFactory >>> for parameter 0 at org.mybatis.guice.SqlSessionManagerProvider.<init>(SqlSessionManagerProvider.java:35) >>> while locating org.mybatis.guice.SqlSessionManagerProvider >>> while locating org.apache.ibatis.session.SqlSessionManager >>> for field at org.mybatis.guice.MapperProvider.sqlSessionManager(MapperProvider.java:42) >>> at org.mybatis.guice.MyBatisModule.bindMapperProvider(MyBatisModule.java:270) >>> >>> 1 error >>> at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:354) >>> at com.google.inject.InjectorBuilder.injectDynamically(InjectorBuilder.java:173) >>> at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:113) >>> at com.google.inject.Guice.createInjector(Guice.java:92) >>> at com.google.inject.Guice.createInjector(Guice.java:69) >>> at com.google.inject.Guice.createInjector(Guice.java:59) >>> at de.fortisit.common.guice.GuiceConfig.getInjector(GuiceConfig.java:32) >>> at com.google.inject.servlet.GuiceServletContextListener.contextInitialized(GuiceServletContextListener.java:43) >>> >>> Here is how I configure guice: >>> public class GuiceConfig extends GuiceServletContextListener { >>> protected Injector getInjector() { >>> >>> //Class<? extends Provider<DataSource>> dataSourceProviderClass = C3p0DataSourceProvider.class; >>> Class<? extends Provider<DataSource>> dataSourceProviderClass = UnpooledDataSourceProvider.class; >>> >>> Class<? extends Provider<TransactionFactory>> txFactoryProviderClass = JdbcTransactionFactoryProvider.class; >>> >>> final Map<String, String> params = new HashMap<String, String>(); >>> params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "de.fortisit.weblog.resources"); >>> >>> Injector injector = Guice.createInjector( >>> new Module() { >>> public void configure(Binder binder) { >>> binder.bindConstant().annotatedWith(Names.named("mybatis.environment.id")).to("development"); >>> binder.bindConstant().annotatedWith(Names.named("JDBC.driver")).to("com.mysql.jdbc.Driver"); >>> binder.bindConstant().annotatedWith(Names.named("JDBC.url")).to("jdbc:mysql://localhost/weblog_dev"); >>> binder.bindConstant().annotatedWith(Names.named("JDBC.username")).to("weblog"); >>> binder.bindConstant().annotatedWith(Names.named("JDBC.password")).to("weblog"); >>> } >>> }, >>> new MyBatisModule(dataSourceProviderClass, txFactoryProviderClass) >>> .addMapperClasses(TaskMapper.class), >>> new Jsr250Module(), >>> new ServletModule() { >>> @Override >>> protected void configureServlets() { >>> serve("/*").with(GuiceContainer.class, params); >>> } >>> } >>> ); >>> >>> SqlSessionFactory sessionFactory = injector.getInstance(SqlSessionFactory.class); >>> System.out.println(sessionFactory); >>> >>> return injector; >>> } >>> } >>> >>> And this is the resource class: >>> @Path("hello") >>> public class HelloResource { >>> private ItemResource item; >>> >>> private TaskMapper taskMapper; // <<<---- This causes the error >>> >>> @Inject >>> public HelloResource(ItemResource item, TaskMapper taskMapper) { >>> this.item = item; >>> //this.taskMapper = taskMapper; >>> } >>> >>> @GET >>> public String index() { >>> //List<TaskDto> tasks = taskMapper.selectAll(); >>> System.out.println("HelloResource.index() invoked..."); >>> return "Hello World"; >>> } >>> >>> I am getting desperate. Any help much appreciated! >>> >> > |
|
Thanks a lot. This is going to be a closed source project, but I am just starting, so I can upload the
project to a public repo. I'll do that this evening. Thanks a million for the offer. -----Ursprüngliche Nachricht----- Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi Gesendet: Montag, 6. September 2010 09:21 An: [hidden email] Betreff: Re: mybatis-guice driving me mad Hi again Stephen, can you check in you're classpath there's no MyBatis 3.0.1 and only 3.0.2? The Mappers auto-injection works with the 3.0.2 only, that's a lack in the documentation. Please let me know, alles gute! Simo http://people.apache.org/~simonetripodi/ http://www.99soft.org/ On Mon, Sep 6, 2010 at 8:13 AM, Simone Tripodi <[hidden email]> wrote: > A trivial question: is this an Open or Closed source project? If open, > I'd more then glad to check it out to help you. > Thanks in advance, > Simo > > http://people.apache.org/~simonetripodi/ > http://www.99soft.org/ > > > > On Mon, Sep 6, 2010 at 7:50 AM, Simone Tripodi <[hidden email]> wrote: >> Hi Stephen, >> I'm studying the case you submitted, just give me the time to provide >> you a valid help! >> Have a nice day, >> Simo >> >> http://people.apache.org/~simonetripodi/ >> http://www.99soft.org/ >> >> >> >> On Mon, Sep 6, 2010 at 1:45 AM, Stephen Friedrich >> <[hidden email]> wrote: >>> My plan was to add mybatis and mybatis-guice to the app described here >>> http://blog.curran.in/2010/02/creating-restful-service-with-jersey.html >>> and use that as a starting point for my own app. >>> >>> The injection of a mapper into a JAX-RS resource class constructor works fine. >>> I can even break into the debugger and successfully use the mapper within the constructor. >>> _But_ as soon as I declare the mapper as a field in the resource class, I get this strange error: >>> >>> com.google.inject.CreationException: Guice creation errors: >>> >>> 1) Error in custom provider, java.lang.NullPointerException >>> while locating org.mybatis.guice.datasource.builtin.UnpooledDataSourceProvider >>> while locating javax.sql.DataSource >>> for parameter 2 at org.mybatis.guice.environment.EnvironmentProvider.<init>(EnvironmentProvider.java:51) >>> while locating org.mybatis.guice.environment.EnvironmentProvider >>> while locating org.apache.ibatis.mapping.Environment >>> for parameter 0 at org.mybatis.guice.configuration.ConfigurationProvider.<init>(ConfigurationProvider.java:52) >>> while locating org.mybatis.guice.configuration.ConfigurationProvider >>> while locating org.apache.ibatis.session.Configuration >>> for parameter 0 at org.mybatis.guice.SqlSessionFactoryProvider.<init>(SqlSessionFactoryProvider.java:45) >>> while locating org.mybatis.guice.SqlSessionFactoryProvider >>> while locating org.apache.ibatis.session.SqlSessionFactory >>> for parameter 0 at org.mybatis.guice.SqlSessionManagerProvider.<init>(SqlSessionManagerProvider.java:35) >>> while locating org.mybatis.guice.SqlSessionManagerProvider >>> while locating org.apache.ibatis.session.SqlSessionManager >>> for field at org.mybatis.guice.MapperProvider.sqlSessionManager(MapperProvider.java:42) >>> at org.mybatis.guice.MyBatisModule.bindMapperProvider(MyBatisModule.java:270) >>> >>> 1 error >>> at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:354) >>> at com.google.inject.InjectorBuilder.injectDynamically(InjectorBuilder.java:173) >>> at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:113) >>> at com.google.inject.Guice.createInjector(Guice.java:92) >>> at com.google.inject.Guice.createInjector(Guice.java:69) >>> at com.google.inject.Guice.createInjector(Guice.java:59) >>> at de.fortisit.common.guice.GuiceConfig.getInjector(GuiceConfig.java:32) >>> at com.google.inject.servlet.GuiceServletContextListener.contextInitialized(GuiceServletContextListener.java:43) >>> >>> Here is how I configure guice: >>> public class GuiceConfig extends GuiceServletContextListener { >>> protected Injector getInjector() { >>> >>> //Class<? extends Provider<DataSource>> dataSourceProviderClass = C3p0DataSourceProvider.class; >>> Class<? extends Provider<DataSource>> dataSourceProviderClass = UnpooledDataSourceProvider.class; >>> >>> Class<? extends Provider<TransactionFactory>> txFactoryProviderClass = JdbcTransactionFactoryProvider.class; >>> >>> final Map<String, String> params = new HashMap<String, String>(); >>> params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "de.fortisit.weblog.resources"); >>> >>> Injector injector = Guice.createInjector( >>> new Module() { >>> public void configure(Binder binder) { >>> binder.bindConstant().annotatedWith(Names.named("mybatis.environment.id")).to("development"); >>> binder.bindConstant().annotatedWith(Names.named("JDBC.driver")).to("com.mysql.jdbc.Driver"); >>> binder.bindConstant().annotatedWith(Names.named("JDBC.url")).to("jdbc:mysql://localhost/weblog_dev"); >>> binder.bindConstant().annotatedWith(Names.named("JDBC.username")).to("weblog"); >>> binder.bindConstant().annotatedWith(Names.named("JDBC.password")).to("weblog"); >>> } >>> }, >>> new MyBatisModule(dataSourceProviderClass, txFactoryProviderClass) >>> .addMapperClasses(TaskMapper.class), >>> new Jsr250Module(), >>> new ServletModule() { >>> @Override >>> protected void configureServlets() { >>> serve("/*").with(GuiceContainer.class, params); >>> } >>> } >>> ); >>> >>> SqlSessionFactory sessionFactory = injector.getInstance(SqlSessionFactory.class); >>> System.out.println(sessionFactory); >>> >>> return injector; >>> } >>> } >>> >>> And this is the resource class: >>> @Path("hello") >>> public class HelloResource { >>> private ItemResource item; >>> >>> private TaskMapper taskMapper; // <<<---- This causes the error >>> >>> @Inject >>> public HelloResource(ItemResource item, TaskMapper taskMapper) { >>> this.item = item; >>> //this.taskMapper = taskMapper; >>> } >>> >>> @GET >>> public String index() { >>> //List<TaskDto> tasks = taskMapper.selectAll(); >>> System.out.println("HelloResource.index() invoked..."); >>> return "Hello World"; >>> } >>> >>> I am getting desperate. Any help much appreciated! >>> >> > |
|
HI Stephen,
you're welcome, btw to avoid spending efforts check the used MyBatis version first and make sure you're using the 3.0.2, if it doesn't work I'm more than pleased to help you. Alles gute! Simo http://people.apache.org/~simonetripodi/ http://www.99soft.org/ On Mon, Sep 6, 2010 at 7:32 PM, Stephen Friedrich <[hidden email]> wrote: > Thanks a lot. This is going to be a closed source project, but I am just starting, so I can upload the > project to a public repo. I'll do that this evening. > Thanks a million for the offer. > > -----Ursprüngliche Nachricht----- > Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi > Gesendet: Montag, 6. September 2010 09:21 > An: [hidden email] > Betreff: Re: mybatis-guice driving me mad > > Hi again Stephen, > can you check in you're classpath there's no MyBatis 3.0.1 and only > 3.0.2? The Mappers auto-injection works with the 3.0.2 only, that's a > lack in the documentation. > Please let me know, alles gute! > Simo > > http://people.apache.org/~simonetripodi/ > http://www.99soft.org/ > > > > On Mon, Sep 6, 2010 at 8:13 AM, Simone Tripodi <[hidden email]> wrote: >> A trivial question: is this an Open or Closed source project? If open, >> I'd more then glad to check it out to help you. >> Thanks in advance, >> Simo >> >> http://people.apache.org/~simonetripodi/ >> http://www.99soft.org/ >> >> >> >> On Mon, Sep 6, 2010 at 7:50 AM, Simone Tripodi <[hidden email]> wrote: >>> Hi Stephen, >>> I'm studying the case you submitted, just give me the time to provide >>> you a valid help! >>> Have a nice day, >>> Simo >>> >>> http://people.apache.org/~simonetripodi/ >>> http://www.99soft.org/ >>> >>> >>> >>> On Mon, Sep 6, 2010 at 1:45 AM, Stephen Friedrich >>> <[hidden email]> wrote: >>>> My plan was to add mybatis and mybatis-guice to the app described here >>>> http://blog.curran.in/2010/02/creating-restful-service-with-jersey.html >>>> and use that as a starting point for my own app. >>>> >>>> The injection of a mapper into a JAX-RS resource class constructor works fine. >>>> I can even break into the debugger and successfully use the mapper within the constructor. >>>> _But_ as soon as I declare the mapper as a field in the resource class, I get this strange error: >>>> >>>> com.google.inject.CreationException: Guice creation errors: >>>> >>>> 1) Error in custom provider, java.lang.NullPointerException >>>> while locating org.mybatis.guice.datasource.builtin.UnpooledDataSourceProvider >>>> while locating javax.sql.DataSource >>>> for parameter 2 at org.mybatis.guice.environment.EnvironmentProvider.<init>(EnvironmentProvider.java:51) >>>> while locating org.mybatis.guice.environment.EnvironmentProvider >>>> while locating org.apache.ibatis.mapping.Environment >>>> for parameter 0 at org.mybatis.guice.configuration.ConfigurationProvider.<init>(ConfigurationProvider.java:52) >>>> while locating org.mybatis.guice.configuration.ConfigurationProvider >>>> while locating org.apache.ibatis.session.Configuration >>>> for parameter 0 at org.mybatis.guice.SqlSessionFactoryProvider.<init>(SqlSessionFactoryProvider.java:45) >>>> while locating org.mybatis.guice.SqlSessionFactoryProvider >>>> while locating org.apache.ibatis.session.SqlSessionFactory >>>> for parameter 0 at org.mybatis.guice.SqlSessionManagerProvider.<init>(SqlSessionManagerProvider.java:35) >>>> while locating org.mybatis.guice.SqlSessionManagerProvider >>>> while locating org.apache.ibatis.session.SqlSessionManager >>>> for field at org.mybatis.guice.MapperProvider.sqlSessionManager(MapperProvider.java:42) >>>> at org.mybatis.guice.MyBatisModule.bindMapperProvider(MyBatisModule.java:270) >>>> >>>> 1 error >>>> at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:354) >>>> at com.google.inject.InjectorBuilder.injectDynamically(InjectorBuilder.java:173) >>>> at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:113) >>>> at com.google.inject.Guice.createInjector(Guice.java:92) >>>> at com.google.inject.Guice.createInjector(Guice.java:69) >>>> at com.google.inject.Guice.createInjector(Guice.java:59) >>>> at de.fortisit.common.guice.GuiceConfig.getInjector(GuiceConfig.java:32) >>>> at com.google.inject.servlet.GuiceServletContextListener.contextInitialized(GuiceServletContextListener.java:43) >>>> >>>> Here is how I configure guice: >>>> public class GuiceConfig extends GuiceServletContextListener { >>>> protected Injector getInjector() { >>>> >>>> //Class<? extends Provider<DataSource>> dataSourceProviderClass = C3p0DataSourceProvider.class; >>>> Class<? extends Provider<DataSource>> dataSourceProviderClass = UnpooledDataSourceProvider.class; >>>> >>>> Class<? extends Provider<TransactionFactory>> txFactoryProviderClass = JdbcTransactionFactoryProvider.class; >>>> >>>> final Map<String, String> params = new HashMap<String, String>(); >>>> params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "de.fortisit.weblog.resources"); >>>> >>>> Injector injector = Guice.createInjector( >>>> new Module() { >>>> public void configure(Binder binder) { >>>> binder.bindConstant().annotatedWith(Names.named("mybatis.environment.id")).to("development"); >>>> binder.bindConstant().annotatedWith(Names.named("JDBC.driver")).to("com.mysql.jdbc.Driver"); >>>> binder.bindConstant().annotatedWith(Names.named("JDBC.url")).to("jdbc:mysql://localhost/weblog_dev"); >>>> binder.bindConstant().annotatedWith(Names.named("JDBC.username")).to("weblog"); >>>> binder.bindConstant().annotatedWith(Names.named("JDBC.password")).to("weblog"); >>>> } >>>> }, >>>> new MyBatisModule(dataSourceProviderClass, txFactoryProviderClass) >>>> .addMapperClasses(TaskMapper.class), >>>> new Jsr250Module(), >>>> new ServletModule() { >>>> @Override >>>> protected void configureServlets() { >>>> serve("/*").with(GuiceContainer.class, params); >>>> } >>>> } >>>> ); >>>> >>>> SqlSessionFactory sessionFactory = injector.getInstance(SqlSessionFactory.class); >>>> System.out.println(sessionFactory); >>>> >>>> return injector; >>>> } >>>> } >>>> >>>> And this is the resource class: >>>> @Path("hello") >>>> public class HelloResource { >>>> private ItemResource item; >>>> >>>> private TaskMapper taskMapper; // <<<---- This causes the error >>>> >>>> @Inject >>>> public HelloResource(ItemResource item, TaskMapper taskMapper) { >>>> this.item = item; >>>> //this.taskMapper = taskMapper; >>>> } >>>> >>>> @GET >>>> public String index() { >>>> //List<TaskDto> tasks = taskMapper.selectAll(); >>>> System.out.println("HelloResource.index() invoked..."); >>>> return "Hello World"; >>>> } >>>> >>>> I am getting desperate. Any help much appreciated! >>>> >>> >> > |
|
Thanks - got it working!
The problem was not with outdated mybatis version (I never had anything older than 3.0.2 in the classpath), but I guess due to an outdated Jersey version (1.1.5). Sorry for blaming mybatis-guice! Now I've got a working, self contained example using Jersey - JAX-RS (REST-style web services) Jackson - JSON encoding Guice - Dependency Injection GuiceyFruit - Lifecycle Annotations MyBatis - Java/DB mapping MyBatis-Guice - Integrating MyBatis with Guice C3P0 - Connection Pooling H2DB - In-memory DB to isolate the example ExtJS - Just for a simple table to show the result of a JAX-RS call The example project is at http://eekboom.de/jamyguice.zip (currently only with project setup for IDEA 9 - no ant or maven build yet). The deployable WAR (tested on Tomcat 6) is at http://eekboom.de/jamyguice.war Maybe this can help somebody else. -- Stephen -----Ursprüngliche Nachricht----- Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi Gesendet: Montag, 6. September 2010 21:58 An: [hidden email] Betreff: Re: mybatis-guice driving me mad HI Stephen, you're welcome, btw to avoid spending efforts check the used MyBatis version first and make sure you're using the 3.0.2, if it doesn't work I'm more than pleased to help you. Alles gute! Simo http://people.apache.org/~simonetripodi/ http://www.99soft.org/ On Mon, Sep 6, 2010 at 7:32 PM, Stephen Friedrich <[hidden email]> wrote: > Thanks a lot. This is going to be a closed source project, but I am just starting, so I can upload the > project to a public repo. I'll do that this evening. > Thanks a million for the offer. > > -----Ursprüngliche Nachricht----- > Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi > Gesendet: Montag, 6. September 2010 09:21 > An: [hidden email] > Betreff: Re: mybatis-guice driving me mad > > Hi again Stephen, > can you check in you're classpath there's no MyBatis 3.0.1 and only > 3.0.2? The Mappers auto-injection works with the 3.0.2 only, that's a > lack in the documentation. > Please let me know, alles gute! > Simo > > http://people.apache.org/~simonetripodi/ > http://www.99soft.org/ > > > > On Mon, Sep 6, 2010 at 8:13 AM, Simone Tripodi <[hidden email]> wrote: >> A trivial question: is this an Open or Closed source project? If open, >> I'd more then glad to check it out to help you. >> Thanks in advance, >> Simo >> >> http://people.apache.org/~simonetripodi/ >> http://www.99soft.org/ >> >> >> >> On Mon, Sep 6, 2010 at 7:50 AM, Simone Tripodi <[hidden email]> wrote: >>> Hi Stephen, >>> I'm studying the case you submitted, just give me the time to provide >>> you a valid help! >>> Have a nice day, >>> Simo >>> >>> http://people.apache.org/~simonetripodi/ >>> http://www.99soft.org/ >>> >>> >>> >>> On Mon, Sep 6, 2010 at 1:45 AM, Stephen Friedrich >>> <[hidden email]> wrote: >>>> My plan was to add mybatis and mybatis-guice to the app described here >>>> http://blog.curran.in/2010/02/creating-restful-service-with-jersey.html >>>> and use that as a starting point for my own app. >>>> >>>> The injection of a mapper into a JAX-RS resource class constructor works fine. >>>> I can even break into the debugger and successfully use the mapper within the constructor. >>>> _But_ as soon as I declare the mapper as a field in the resource class, I get this strange error: >>>> >>>> com.google.inject.CreationException: Guice creation errors: >>>> >>>> 1) Error in custom provider, java.lang.NullPointerException >>>> while locating org.mybatis.guice.datasource.builtin.UnpooledDataSourceProvider >>>> while locating javax.sql.DataSource >>>> for parameter 2 at org.mybatis.guice.environment.EnvironmentProvider.<init>(EnvironmentProvider.java:51) >>>> while locating org.mybatis.guice.environment.EnvironmentProvider >>>> while locating org.apache.ibatis.mapping.Environment >>>> for parameter 0 at org.mybatis.guice.configuration.ConfigurationProvider.<init>(ConfigurationProvider.java:52) >>>> while locating org.mybatis.guice.configuration.ConfigurationProvider >>>> while locating org.apache.ibatis.session.Configuration >>>> for parameter 0 at org.mybatis.guice.SqlSessionFactoryProvider.<init>(SqlSessionFactoryProvider.java:45) >>>> while locating org.mybatis.guice.SqlSessionFactoryProvider >>>> while locating org.apache.ibatis.session.SqlSessionFactory >>>> for parameter 0 at org.mybatis.guice.SqlSessionManagerProvider.<init>(SqlSessionManagerProvider.java:35) >>>> while locating org.mybatis.guice.SqlSessionManagerProvider >>>> while locating org.apache.ibatis.session.SqlSessionManager >>>> for field at org.mybatis.guice.MapperProvider.sqlSessionManager(MapperProvider.java:42) >>>> at org.mybatis.guice.MyBatisModule.bindMapperProvider(MyBatisModule.java:270) >>>> >>>> 1 error >>>> at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:354) >>>> at com.google.inject.InjectorBuilder.injectDynamically(InjectorBuilder.java:173) >>>> at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:113) >>>> at com.google.inject.Guice.createInjector(Guice.java:92) >>>> at com.google.inject.Guice.createInjector(Guice.java:69) >>>> at com.google.inject.Guice.createInjector(Guice.java:59) >>>> at de.fortisit.common.guice.GuiceConfig.getInjector(GuiceConfig.java:32) >>>> at com.google.inject.servlet.GuiceServletContextListener.contextInitialized(GuiceServletContextListener.java:43) >>>> >>>> Here is how I configure guice: >>>> public class GuiceConfig extends GuiceServletContextListener { >>>> protected Injector getInjector() { >>>> >>>> //Class<? extends Provider<DataSource>> dataSourceProviderClass = C3p0DataSourceProvider.class; >>>> Class<? extends Provider<DataSource>> dataSourceProviderClass = UnpooledDataSourceProvider.class; >>>> >>>> Class<? extends Provider<TransactionFactory>> txFactoryProviderClass = JdbcTransactionFactoryProvider.class; >>>> >>>> final Map<String, String> params = new HashMap<String, String>(); >>>> params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "de.fortisit.weblog.resources"); >>>> >>>> Injector injector = Guice.createInjector( >>>> new Module() { >>>> public void configure(Binder binder) { >>>> binder.bindConstant().annotatedWith(Names.named("mybatis.environment.id")).to("development"); >>>> binder.bindConstant().annotatedWith(Names.named("JDBC.driver")).to("com.mysql.jdbc.Driver"); >>>> binder.bindConstant().annotatedWith(Names.named("JDBC.url")).to("jdbc:mysql://localhost/weblog_dev"); >>>> binder.bindConstant().annotatedWith(Names.named("JDBC.username")).to("weblog"); >>>> binder.bindConstant().annotatedWith(Names.named("JDBC.password")).to("weblog"); >>>> } >>>> }, >>>> new MyBatisModule(dataSourceProviderClass, txFactoryProviderClass) >>>> .addMapperClasses(TaskMapper.class), >>>> new Jsr250Module(), >>>> new ServletModule() { >>>> @Override >>>> protected void configureServlets() { >>>> serve("/*").with(GuiceContainer.class, params); >>>> } >>>> } >>>> ); >>>> >>>> SqlSessionFactory sessionFactory = injector.getInstance(SqlSessionFactory.class); >>>> System.out.println(sessionFactory); >>>> >>>> return injector; >>>> } >>>> } >>>> >>>> And this is the resource class: >>>> @Path("hello") >>>> public class HelloResource { >>>> private ItemResource item; >>>> >>>> private TaskMapper taskMapper; // <<<---- This causes the error >>>> >>>> @Inject >>>> public HelloResource(ItemResource item, TaskMapper taskMapper) { >>>> this.item = item; >>>> //this.taskMapper = taskMapper; >>>> } >>>> >>>> @GET >>>> public String index() { >>>> //List<TaskDto> tasks = taskMapper.selectAll(); >>>> System.out.println("HelloResource.index() invoked..."); >>>> return "Hello World"; >>>> } >>>> >>>> I am getting desperate. Any help much appreciated! >>>> >>> >> > |
|
Hi Stephen,
all's well that ends well, nice to hear you resolved the issue :) Don't worry about blaming mybatis-guice, I think it was natural consequence since the stacktrace only indicated the related components :P Have a nice day, alles gute! Simo http://people.apache.org/~simonetripodi/ http://www.99soft.org/ On Tue, Sep 7, 2010 at 12:58 AM, Stephen Friedrich <[hidden email]> wrote: > Thanks - got it working! > The problem was not with outdated mybatis version (I never had anything older than 3.0.2 in the classpath), but I guess due to an outdated Jersey version (1.1.5). > Sorry for blaming mybatis-guice! > > Now I've got a working, self contained example using > Jersey - JAX-RS (REST-style web services) > Jackson - JSON encoding > Guice - Dependency Injection > GuiceyFruit - Lifecycle Annotations > MyBatis - Java/DB mapping > MyBatis-Guice - Integrating MyBatis with Guice > C3P0 - Connection Pooling > H2DB - In-memory DB to isolate the example > ExtJS - Just for a simple table to show the result of a JAX-RS call > > The example project is at http://eekboom.de/jamyguice.zip (currently only with project setup for IDEA 9 - no ant or maven build yet). > The deployable WAR (tested on Tomcat 6) is at http://eekboom.de/jamyguice.war > > Maybe this can help somebody else. > > -- Stephen > > -----Ursprüngliche Nachricht----- > Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi > Gesendet: Montag, 6. September 2010 21:58 > An: [hidden email] > Betreff: Re: mybatis-guice driving me mad > > HI Stephen, > you're welcome, btw to avoid spending efforts check the used MyBatis > version first and make sure you're using the 3.0.2, if it doesn't work > I'm more than pleased to help you. > Alles gute! > Simo > > http://people.apache.org/~simonetripodi/ > http://www.99soft.org/ > > > > On Mon, Sep 6, 2010 at 7:32 PM, Stephen Friedrich > <[hidden email]> wrote: >> Thanks a lot. This is going to be a closed source project, but I am just starting, so I can upload the >> project to a public repo. I'll do that this evening. >> Thanks a million for the offer. >> >> -----Ursprüngliche Nachricht----- >> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi >> Gesendet: Montag, 6. September 2010 09:21 >> An: [hidden email] >> Betreff: Re: mybatis-guice driving me mad >> >> Hi again Stephen, >> can you check in you're classpath there's no MyBatis 3.0.1 and only >> 3.0.2? The Mappers auto-injection works with the 3.0.2 only, that's a >> lack in the documentation. >> Please let me know, alles gute! >> Simo >> >> http://people.apache.org/~simonetripodi/ >> http://www.99soft.org/ >> >> >> >> On Mon, Sep 6, 2010 at 8:13 AM, Simone Tripodi <[hidden email]> wrote: >>> A trivial question: is this an Open or Closed source project? If open, >>> I'd more then glad to check it out to help you. >>> Thanks in advance, >>> Simo >>> >>> http://people.apache.org/~simonetripodi/ >>> http://www.99soft.org/ >>> >>> >>> >>> On Mon, Sep 6, 2010 at 7:50 AM, Simone Tripodi <[hidden email]> wrote: >>>> Hi Stephen, >>>> I'm studying the case you submitted, just give me the time to provide >>>> you a valid help! >>>> Have a nice day, >>>> Simo >>>> >>>> http://people.apache.org/~simonetripodi/ >>>> http://www.99soft.org/ >>>> >>>> >>>> >>>> On Mon, Sep 6, 2010 at 1:45 AM, Stephen Friedrich >>>> <[hidden email]> wrote: >>>>> My plan was to add mybatis and mybatis-guice to the app described here >>>>> http://blog.curran.in/2010/02/creating-restful-service-with-jersey.html >>>>> and use that as a starting point for my own app. >>>>> >>>>> The injection of a mapper into a JAX-RS resource class constructor works fine. >>>>> I can even break into the debugger and successfully use the mapper within the constructor. >>>>> _But_ as soon as I declare the mapper as a field in the resource class, I get this strange error: >>>>> >>>>> com.google.inject.CreationException: Guice creation errors: >>>>> >>>>> 1) Error in custom provider, java.lang.NullPointerException >>>>> while locating org.mybatis.guice.datasource.builtin.UnpooledDataSourceProvider >>>>> while locating javax.sql.DataSource >>>>> for parameter 2 at org.mybatis.guice.environment.EnvironmentProvider.<init>(EnvironmentProvider.java:51) >>>>> while locating org.mybatis.guice.environment.EnvironmentProvider >>>>> while locating org.apache.ibatis.mapping.Environment >>>>> for parameter 0 at org.mybatis.guice.configuration.ConfigurationProvider.<init>(ConfigurationProvider.java:52) >>>>> while locating org.mybatis.guice.configuration.ConfigurationProvider >>>>> while locating org.apache.ibatis.session.Configuration >>>>> for parameter 0 at org.mybatis.guice.SqlSessionFactoryProvider.<init>(SqlSessionFactoryProvider.java:45) >>>>> while locating org.mybatis.guice.SqlSessionFactoryProvider >>>>> while locating org.apache.ibatis.session.SqlSessionFactory >>>>> for parameter 0 at org.mybatis.guice.SqlSessionManagerProvider.<init>(SqlSessionManagerProvider.java:35) >>>>> while locating org.mybatis.guice.SqlSessionManagerProvider >>>>> while locating org.apache.ibatis.session.SqlSessionManager >>>>> for field at org.mybatis.guice.MapperProvider.sqlSessionManager(MapperProvider.java:42) >>>>> at org.mybatis.guice.MyBatisModule.bindMapperProvider(MyBatisModule.java:270) >>>>> >>>>> 1 error >>>>> at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:354) >>>>> at com.google.inject.InjectorBuilder.injectDynamically(InjectorBuilder.java:173) >>>>> at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:113) >>>>> at com.google.inject.Guice.createInjector(Guice.java:92) >>>>> at com.google.inject.Guice.createInjector(Guice.java:69) >>>>> at com.google.inject.Guice.createInjector(Guice.java:59) >>>>> at de.fortisit.common.guice.GuiceConfig.getInjector(GuiceConfig.java:32) >>>>> at com.google.inject.servlet.GuiceServletContextListener.contextInitialized(GuiceServletContextListener.java:43) >>>>> >>>>> Here is how I configure guice: >>>>> public class GuiceConfig extends GuiceServletContextListener { >>>>> protected Injector getInjector() { >>>>> >>>>> //Class<? extends Provider<DataSource>> dataSourceProviderClass = C3p0DataSourceProvider.class; >>>>> Class<? extends Provider<DataSource>> dataSourceProviderClass = UnpooledDataSourceProvider.class; >>>>> >>>>> Class<? extends Provider<TransactionFactory>> txFactoryProviderClass = JdbcTransactionFactoryProvider.class; >>>>> >>>>> final Map<String, String> params = new HashMap<String, String>(); >>>>> params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "de.fortisit.weblog.resources"); >>>>> >>>>> Injector injector = Guice.createInjector( >>>>> new Module() { >>>>> public void configure(Binder binder) { >>>>> binder.bindConstant().annotatedWith(Names.named("mybatis.environment.id")).to("development"); >>>>> binder.bindConstant().annotatedWith(Names.named("JDBC.driver")).to("com.mysql.jdbc.Driver"); >>>>> binder.bindConstant().annotatedWith(Names.named("JDBC.url")).to("jdbc:mysql://localhost/weblog_dev"); >>>>> binder.bindConstant().annotatedWith(Names.named("JDBC.username")).to("weblog"); >>>>> binder.bindConstant().annotatedWith(Names.named("JDBC.password")).to("weblog"); >>>>> } >>>>> }, >>>>> new MyBatisModule(dataSourceProviderClass, txFactoryProviderClass) >>>>> .addMapperClasses(TaskMapper.class), >>>>> new Jsr250Module(), >>>>> new ServletModule() { >>>>> @Override >>>>> protected void configureServlets() { >>>>> serve("/*").with(GuiceContainer.class, params); >>>>> } >>>>> } >>>>> ); >>>>> >>>>> SqlSessionFactory sessionFactory = injector.getInstance(SqlSessionFactory.class); >>>>> System.out.println(sessionFactory); >>>>> >>>>> return injector; >>>>> } >>>>> } >>>>> >>>>> And this is the resource class: >>>>> @Path("hello") >>>>> public class HelloResource { >>>>> private ItemResource item; >>>>> >>>>> private TaskMapper taskMapper; // <<<---- This causes the error >>>>> >>>>> @Inject >>>>> public HelloResource(ItemResource item, TaskMapper taskMapper) { >>>>> this.item = item; >>>>> //this.taskMapper = taskMapper; >>>>> } >>>>> >>>>> @GET >>>>> public String index() { >>>>> //List<TaskDto> tasks = taskMapper.selectAll(); >>>>> System.out.println("HelloResource.index() invoked..."); >>>>> return "Hello World"; >>>>> } >>>>> >>>>> I am getting desperate. Any help much appreciated! >>>>> >>>> >>> >> > |
|
Oh my, when I switched back from H2 to Oracle the error re-appeared :-(
It seems somebody does not like the Oracle connection info hardcoded - the error was somehow related to injecting JDBC.username into javax.sql.DataSource. No idea why there should be a different in between JDBC drivers?! All I changed compared was the connection info (URL, driver, username, password) that is hardcoded in GuiceConfig in my example at http://eekboom.de/jamyguice.zip After I configured the datasource as a resource in tomcat's context.xml and used JndiProvider instead of C3p0DataSourceProvider or UnpooledDataSourceProvider it (hopefully finally) works again. -- Stephen -----Ursprüngliche Nachricht----- Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi Gesendet: Dienstag, 7. September 2010 07:24 An: [hidden email] Betreff: Re: mybatis-guice driving me mad Hi Stephen, all's well that ends well, nice to hear you resolved the issue :) Don't worry about blaming mybatis-guice, I think it was natural consequence since the stacktrace only indicated the related components :P Have a nice day, alles gute! Simo http://people.apache.org/~simonetripodi/ http://www.99soft.org/ On Tue, Sep 7, 2010 at 12:58 AM, Stephen Friedrich <[hidden email]> wrote: > Thanks - got it working! > The problem was not with outdated mybatis version (I never had anything older than 3.0.2 in the classpath), but I guess due to an outdated Jersey version (1.1.5). > Sorry for blaming mybatis-guice! > > Now I've got a working, self contained example using > Jersey - JAX-RS (REST-style web services) > Jackson - JSON encoding > Guice - Dependency Injection > GuiceyFruit - Lifecycle Annotations > MyBatis - Java/DB mapping > MyBatis-Guice - Integrating MyBatis with Guice > C3P0 - Connection Pooling > H2DB - In-memory DB to isolate the example > ExtJS - Just for a simple table to show the result of a JAX-RS call > > The example project is at http://eekboom.de/jamyguice.zip (currently only with project setup for IDEA 9 - no ant or maven build yet). > The deployable WAR (tested on Tomcat 6) is at http://eekboom.de/jamyguice.war > > Maybe this can help somebody else. > > -- Stephen > > -----Ursprüngliche Nachricht----- > Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi > Gesendet: Montag, 6. September 2010 21:58 > An: [hidden email] > Betreff: Re: mybatis-guice driving me mad > > HI Stephen, > you're welcome, btw to avoid spending efforts check the used MyBatis > version first and make sure you're using the 3.0.2, if it doesn't work > I'm more than pleased to help you. > Alles gute! > Simo > > http://people.apache.org/~simonetripodi/ > http://www.99soft.org/ > > > > On Mon, Sep 6, 2010 at 7:32 PM, Stephen Friedrich > <[hidden email]> wrote: >> Thanks a lot. This is going to be a closed source project, but I am just starting, so I can upload the >> project to a public repo. I'll do that this evening. >> Thanks a million for the offer. >> >> -----Ursprüngliche Nachricht----- >> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi >> Gesendet: Montag, 6. September 2010 09:21 >> An: [hidden email] >> Betreff: Re: mybatis-guice driving me mad >> >> Hi again Stephen, >> can you check in you're classpath there's no MyBatis 3.0.1 and only >> 3.0.2? The Mappers auto-injection works with the 3.0.2 only, that's a >> lack in the documentation. >> Please let me know, alles gute! >> Simo >> >> http://people.apache.org/~simonetripodi/ >> http://www.99soft.org/ >> >> >> >> On Mon, Sep 6, 2010 at 8:13 AM, Simone Tripodi <[hidden email]> wrote: >>> A trivial question: is this an Open or Closed source project? If open, >>> I'd more then glad to check it out to help you. >>> Thanks in advance, >>> Simo >>> >>> http://people.apache.org/~simonetripodi/ >>> http://www.99soft.org/ >>> >>> >>> >>> On Mon, Sep 6, 2010 at 7:50 AM, Simone Tripodi <[hidden email]> wrote: >>>> Hi Stephen, >>>> I'm studying the case you submitted, just give me the time to provide >>>> you a valid help! >>>> Have a nice day, >>>> Simo >>>> >>>> http://people.apache.org/~simonetripodi/ >>>> http://www.99soft.org/ >>>> >>>> >>>> >>>> On Mon, Sep 6, 2010 at 1:45 AM, Stephen Friedrich >>>> <[hidden email]> wrote: >>>>> My plan was to add mybatis and mybatis-guice to the app described here >>>>> http://blog.curran.in/2010/02/creating-restful-service-with-jersey.html >>>>> and use that as a starting point for my own app. >>>>> >>>>> The injection of a mapper into a JAX-RS resource class constructor works fine. >>>>> I can even break into the debugger and successfully use the mapper within the constructor. >>>>> _But_ as soon as I declare the mapper as a field in the resource class, I get this strange error: >>>>> >>>>> com.google.inject.CreationException: Guice creation errors: >>>>> >>>>> 1) Error in custom provider, java.lang.NullPointerException >>>>> while locating org.mybatis.guice.datasource.builtin.UnpooledDataSourceProvider >>>>> while locating javax.sql.DataSource >>>>> for parameter 2 at org.mybatis.guice.environment.EnvironmentProvider.<init>(EnvironmentProvider.java:51) >>>>> while locating org.mybatis.guice.environment.EnvironmentProvider >>>>> while locating org.apache.ibatis.mapping.Environment >>>>> for parameter 0 at org.mybatis.guice.configuration.ConfigurationProvider.<init>(ConfigurationProvider.java:52) >>>>> while locating org.mybatis.guice.configuration.ConfigurationProvider >>>>> while locating org.apache.ibatis.session.Configuration >>>>> for parameter 0 at org.mybatis.guice.SqlSessionFactoryProvider.<init>(SqlSessionFactoryProvider.java:45) >>>>> while locating org.mybatis.guice.SqlSessionFactoryProvider >>>>> while locating org.apache.ibatis.session.SqlSessionFactory >>>>> for parameter 0 at org.mybatis.guice.SqlSessionManagerProvider.<init>(SqlSessionManagerProvider.java:35) >>>>> while locating org.mybatis.guice.SqlSessionManagerProvider >>>>> while locating org.apache.ibatis.session.SqlSessionManager >>>>> for field at org.mybatis.guice.MapperProvider.sqlSessionManager(MapperProvider.java:42) >>>>> at org.mybatis.guice.MyBatisModule.bindMapperProvider(MyBatisModule.java:270) >>>>> >>>>> 1 error >>>>> at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:354) >>>>> at com.google.inject.InjectorBuilder.injectDynamically(InjectorBuilder.java:173) >>>>> at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:113) >>>>> at com.google.inject.Guice.createInjector(Guice.java:92) >>>>> at com.google.inject.Guice.createInjector(Guice.java:69) >>>>> at com.google.inject.Guice.createInjector(Guice.java:59) >>>>> at de.fortisit.common.guice.GuiceConfig.getInjector(GuiceConfig.java:32) >>>>> at com.google.inject.servlet.GuiceServletContextListener.contextInitialized(GuiceServletContextListener.java:43) >>>>> >>>>> Here is how I configure guice: >>>>> public class GuiceConfig extends GuiceServletContextListener { >>>>> protected Injector getInjector() { >>>>> >>>>> //Class<? extends Provider<DataSource>> dataSourceProviderClass = C3p0DataSourceProvider.class; >>>>> Class<? extends Provider<DataSource>> dataSourceProviderClass = UnpooledDataSourceProvider.class; >>>>> >>>>> Class<? extends Provider<TransactionFactory>> txFactoryProviderClass = JdbcTransactionFactoryProvider.class; >>>>> >>>>> final Map<String, String> params = new HashMap<String, String>(); >>>>> params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "de.fortisit.weblog.resources"); >>>>> >>>>> Injector injector = Guice.createInjector( >>>>> new Module() { >>>>> public void configure(Binder binder) { >>>>> binder.bindConstant().annotatedWith(Names.named("mybatis.environment.id")).to("development"); >>>>> binder.bindConstant().annotatedWith(Names.named("JDBC.driver")).to("com.mysql.jdbc.Driver"); >>>>> binder.bindConstant().annotatedWith(Names.named("JDBC.url")).to("jdbc:mysql://localhost/weblog_dev"); >>>>> binder.bindConstant().annotatedWith(Names.named("JDBC.username")).to("weblog"); >>>>> binder.bindConstant().annotatedWith(Names.named("JDBC.password")).to("weblog"); >>>>> } >>>>> }, >>>>> new MyBatisModule(dataSourceProviderClass, txFactoryProviderClass) >>>>> .addMapperClasses(TaskMapper.class), >>>>> new Jsr250Module(), >>>>> new ServletModule() { >>>>> @Override >>>>> protected void configureServlets() { >>>>> serve("/*").with(GuiceContainer.class, params); >>>>> } >>>>> } >>>>> ); >>>>> >>>>> SqlSessionFactory sessionFactory = injector.getInstance(SqlSessionFactory.class); >>>>> System.out.println(sessionFactory); >>>>> >>>>> return injector; >>>>> } >>>>> } >>>>> >>>>> And this is the resource class: >>>>> @Path("hello") >>>>> public class HelloResource { >>>>> private ItemResource item; >>>>> >>>>> private TaskMapper taskMapper; // <<<---- This causes the error >>>>> >>>>> @Inject >>>>> public HelloResource(ItemResource item, TaskMapper taskMapper) { >>>>> this.item = item; >>>>> //this.taskMapper = taskMapper; >>>>> } >>>>> >>>>> @GET >>>>> public String index() { >>>>> //List<TaskDto> tasks = taskMapper.selectAll(); >>>>> System.out.println("HelloResource.index() invoked..."); >>>>> return "Hello World"; >>>>> } >>>>> >>>>> I am getting desperate. Any help much appreciated! >>>>> >>>> >>> >> > |
|
Hi Stephen,
do you mean EXACLY the same error? That would drive me crazy too :D OK it's time to download your package and see how I can help you. I'll let you know ASAP, alles gute, Simo http://people.apache.org/~simonetripodi/ http://www.99soft.org/ On Wed, Sep 8, 2010 at 1:28 AM, Stephen Friedrich <[hidden email]> wrote: > Oh my, when I switched back from H2 to Oracle the error re-appeared :-( > It seems somebody does not like the Oracle connection info hardcoded > - the error was somehow related to injecting JDBC.username into javax.sql.DataSource. > No idea why there should be a different in between JDBC drivers?! > All I changed compared was the connection info (URL, driver, username, password) > that is hardcoded in GuiceConfig in my example at http://eekboom.de/jamyguice.zip > > After I configured the datasource as a resource in tomcat's context.xml and used > JndiProvider instead of C3p0DataSourceProvider or UnpooledDataSourceProvider it (hopefully finally) works again. > > -- Stephen > > > -----Ursprüngliche Nachricht----- > Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi > Gesendet: Dienstag, 7. September 2010 07:24 > An: [hidden email] > Betreff: Re: mybatis-guice driving me mad > > Hi Stephen, > all's well that ends well, nice to hear you resolved the issue :) > Don't worry about blaming mybatis-guice, I think it was natural > consequence since the stacktrace only indicated the related components > :P > Have a nice day, alles gute! > Simo > > http://people.apache.org/~simonetripodi/ > http://www.99soft.org/ > > > > On Tue, Sep 7, 2010 at 12:58 AM, Stephen Friedrich > <[hidden email]> wrote: >> Thanks - got it working! >> The problem was not with outdated mybatis version (I never had anything older than 3.0.2 in the classpath), but I guess due to an outdated Jersey version (1.1.5). >> Sorry for blaming mybatis-guice! >> >> Now I've got a working, self contained example using >> Jersey - JAX-RS (REST-style web services) >> Jackson - JSON encoding >> Guice - Dependency Injection >> GuiceyFruit - Lifecycle Annotations >> MyBatis - Java/DB mapping >> MyBatis-Guice - Integrating MyBatis with Guice >> C3P0 - Connection Pooling >> H2DB - In-memory DB to isolate the example >> ExtJS - Just for a simple table to show the result of a JAX-RS call >> >> The example project is at http://eekboom.de/jamyguice.zip (currently only with project setup for IDEA 9 - no ant or maven build yet). >> The deployable WAR (tested on Tomcat 6) is at http://eekboom.de/jamyguice.war >> >> Maybe this can help somebody else. >> >> -- Stephen >> >> -----Ursprüngliche Nachricht----- >> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi >> Gesendet: Montag, 6. September 2010 21:58 >> An: [hidden email] >> Betreff: Re: mybatis-guice driving me mad >> >> HI Stephen, >> you're welcome, btw to avoid spending efforts check the used MyBatis >> version first and make sure you're using the 3.0.2, if it doesn't work >> I'm more than pleased to help you. >> Alles gute! >> Simo >> >> http://people.apache.org/~simonetripodi/ >> http://www.99soft.org/ >> >> >> >> On Mon, Sep 6, 2010 at 7:32 PM, Stephen Friedrich >> <[hidden email]> wrote: >>> Thanks a lot. This is going to be a closed source project, but I am just starting, so I can upload the >>> project to a public repo. I'll do that this evening. >>> Thanks a million for the offer. >>> >>> -----Ursprüngliche Nachricht----- >>> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi >>> Gesendet: Montag, 6. September 2010 09:21 >>> An: [hidden email] >>> Betreff: Re: mybatis-guice driving me mad >>> >>> Hi again Stephen, >>> can you check in you're classpath there's no MyBatis 3.0.1 and only >>> 3.0.2? The Mappers auto-injection works with the 3.0.2 only, that's a >>> lack in the documentation. >>> Please let me know, alles gute! >>> Simo >>> >>> http://people.apache.org/~simonetripodi/ >>> http://www.99soft.org/ >>> >>> >>> >>> On Mon, Sep 6, 2010 at 8:13 AM, Simone Tripodi <[hidden email]> wrote: >>>> A trivial question: is this an Open or Closed source project? If open, >>>> I'd more then glad to check it out to help you. >>>> Thanks in advance, >>>> Simo >>>> >>>> http://people.apache.org/~simonetripodi/ >>>> http://www.99soft.org/ >>>> >>>> >>>> >>>> On Mon, Sep 6, 2010 at 7:50 AM, Simone Tripodi <[hidden email]> wrote: >>>>> Hi Stephen, >>>>> I'm studying the case you submitted, just give me the time to provide >>>>> you a valid help! >>>>> Have a nice day, >>>>> Simo >>>>> >>>>> http://people.apache.org/~simonetripodi/ >>>>> http://www.99soft.org/ >>>>> >>>>> >>>>> >>>>> On Mon, Sep 6, 2010 at 1:45 AM, Stephen Friedrich >>>>> <[hidden email]> wrote: >>>>>> My plan was to add mybatis and mybatis-guice to the app described here >>>>>> http://blog.curran.in/2010/02/creating-restful-service-with-jersey.html >>>>>> and use that as a starting point for my own app. >>>>>> >>>>>> The injection of a mapper into a JAX-RS resource class constructor works fine. >>>>>> I can even break into the debugger and successfully use the mapper within the constructor. >>>>>> _But_ as soon as I declare the mapper as a field in the resource class, I get this strange error: >>>>>> >>>>>> com.google.inject.CreationException: Guice creation errors: >>>>>> >>>>>> 1) Error in custom provider, java.lang.NullPointerException >>>>>> while locating org.mybatis.guice.datasource.builtin.UnpooledDataSourceProvider >>>>>> while locating javax.sql.DataSource >>>>>> for parameter 2 at org.mybatis.guice.environment.EnvironmentProvider.<init>(EnvironmentProvider.java:51) >>>>>> while locating org.mybatis.guice.environment.EnvironmentProvider >>>>>> while locating org.apache.ibatis.mapping.Environment >>>>>> for parameter 0 at org.mybatis.guice.configuration.ConfigurationProvider.<init>(ConfigurationProvider.java:52) >>>>>> while locating org.mybatis.guice.configuration.ConfigurationProvider >>>>>> while locating org.apache.ibatis.session.Configuration >>>>>> for parameter 0 at org.mybatis.guice.SqlSessionFactoryProvider.<init>(SqlSessionFactoryProvider.java:45) >>>>>> while locating org.mybatis.guice.SqlSessionFactoryProvider >>>>>> while locating org.apache.ibatis.session.SqlSessionFactory >>>>>> for parameter 0 at org.mybatis.guice.SqlSessionManagerProvider.<init>(SqlSessionManagerProvider.java:35) >>>>>> while locating org.mybatis.guice.SqlSessionManagerProvider >>>>>> while locating org.apache.ibatis.session.SqlSessionManager >>>>>> for field at org.mybatis.guice.MapperProvider.sqlSessionManager(MapperProvider.java:42) >>>>>> at org.mybatis.guice.MyBatisModule.bindMapperProvider(MyBatisModule.java:270) >>>>>> >>>>>> 1 error >>>>>> at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:354) >>>>>> at com.google.inject.InjectorBuilder.injectDynamically(InjectorBuilder.java:173) >>>>>> at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:113) >>>>>> at com.google.inject.Guice.createInjector(Guice.java:92) >>>>>> at com.google.inject.Guice.createInjector(Guice.java:69) >>>>>> at com.google.inject.Guice.createInjector(Guice.java:59) >>>>>> at de.fortisit.common.guice.GuiceConfig.getInjector(GuiceConfig.java:32) >>>>>> at com.google.inject.servlet.GuiceServletContextListener.contextInitialized(GuiceServletContextListener.java:43) >>>>>> >>>>>> Here is how I configure guice: >>>>>> public class GuiceConfig extends GuiceServletContextListener { >>>>>> protected Injector getInjector() { >>>>>> >>>>>> //Class<? extends Provider<DataSource>> dataSourceProviderClass = C3p0DataSourceProvider.class; >>>>>> Class<? extends Provider<DataSource>> dataSourceProviderClass = UnpooledDataSourceProvider.class; >>>>>> >>>>>> Class<? extends Provider<TransactionFactory>> txFactoryProviderClass = JdbcTransactionFactoryProvider.class; >>>>>> >>>>>> final Map<String, String> params = new HashMap<String, String>(); >>>>>> params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "de.fortisit.weblog.resources"); >>>>>> >>>>>> Injector injector = Guice.createInjector( >>>>>> new Module() { >>>>>> public void configure(Binder binder) { >>>>>> binder.bindConstant().annotatedWith(Names.named("mybatis.environment.id")).to("development"); >>>>>> binder.bindConstant().annotatedWith(Names.named("JDBC.driver")).to("com.mysql.jdbc.Driver"); >>>>>> binder.bindConstant().annotatedWith(Names.named("JDBC.url")).to("jdbc:mysql://localhost/weblog_dev"); >>>>>> binder.bindConstant().annotatedWith(Names.named("JDBC.username")).to("weblog"); >>>>>> binder.bindConstant().annotatedWith(Names.named("JDBC.password")).to("weblog"); >>>>>> } >>>>>> }, >>>>>> new MyBatisModule(dataSourceProviderClass, txFactoryProviderClass) >>>>>> .addMapperClasses(TaskMapper.class), >>>>>> new Jsr250Module(), >>>>>> new ServletModule() { >>>>>> @Override >>>>>> protected void configureServlets() { >>>>>> serve("/*").with(GuiceContainer.class, params); >>>>>> } >>>>>> } >>>>>> ); >>>>>> >>>>>> SqlSessionFactory sessionFactory = injector.getInstance(SqlSessionFactory.class); >>>>>> System.out.println(sessionFactory); >>>>>> >>>>>> return injector; >>>>>> } >>>>>> } >>>>>> >>>>>> And this is the resource class: >>>>>> @Path("hello") >>>>>> public class HelloResource { >>>>>> private ItemResource item; >>>>>> >>>>>> private TaskMapper taskMapper; // <<<---- This causes the error >>>>>> >>>>>> @Inject >>>>>> public HelloResource(ItemResource item, TaskMapper taskMapper) { >>>>>> this.item = item; >>>>>> //this.taskMapper = taskMapper; >>>>>> } >>>>>> >>>>>> @GET >>>>>> public String index() { >>>>>> //List<TaskDto> tasks = taskMapper.selectAll(); >>>>>> System.out.println("HelloResource.index() invoked..."); >>>>>> return "Hello World"; >>>>>> } >>>>>> >>>>>> I am getting desperate. Any help much appreciated! >>>>>> >>>>> >>>> >>> >> > |
| Powered by Nabble | Edit this page |
