Redis dependencies not resolving hence autowiring seems to be failing
Having worked on a production Spring boot project since almost a year, I am still having a tough time resolving dependencies in a Spring boot project.
Redis read/write is working fine for one module in our project. All I am trying to do, is to implement it in another. I followed the working module.
Following is pom of the working module (where the @Component is defined) -
Module 1's pom -
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.someproject.dependencies</groupId>
<artifactId>someproject-spring-dependencies</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>$project.groupId</groupId>
<artifactId>someproject-common</artifactId>
<version>$project.version</version>
<exclusions>
</dependency>
</dependencies>
In pom of someproject-spring-dependencies -
<redis.clients.jedis.version>2.7.3</redis.clients.jedis.version>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>$jedis.version</version>
</dependency>
And in pom of someproject-common -
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<type>jar</type>
<scope>compile</scope>
</dependency>
I am not sure which of these jedis definitions actually works.
The pom of module 2 is similar to module 1. However, when I try to do the following, in the @Component annotated class of module 2, I get null against object of Autowired RedisDao object, which seems to be a wrapper implementation around the redis.clients package. Trying to give an idea of the same -
- RedisDAOImpl implements RedisDAO. RedisDAOImpl has @Autowired RedisTemplate.
RedisTemplate, another wrapper extends RedisBase. RedisBase implements DisposableBean and has autowired JedisPool, which is within package redis.clients.jedis. RedisTemplate has following call -
Jedis jedis = this.jedisPool.getResource();
Jedis is in package redis.clients.jedis.
- jedisPool is of type JedisPool, annotated as autowired.
- JedisPool is in package package redis.clients.jedis.
Following is the code in the component of module 2, for which the auto wiring seems to be failing -
import com.citruspay.prepaid.common.cache.settings.RedisDAO;
@Component
public class CachedWithdrawalTxnRepository implements CachedWithdrawalTxnDao {
private static final Logger logger = LoggerFactory.getLogger(CachedWithdrawalTxnRepository.class);
@Autowired RedisDAO redis;
@Override
public void create(String uuid)
// TODO Auto-generated method stub
try
redis.setex("withdrawal:"+uuid, 300, "true");
catch(Exception ex)
logger.error(ex.getMessage());
The redis object shows null and I get a null pointer exception.
I am not sure how to debug further.
Update
Answering @Grinish Nepal -
The parent package is being component scanned in the App.java class which is annotated with @SpringBootApplication -
@ComponentScan("com.someproject")
The class where I am Autowiring RedisDAO is in package com.someproject.prepaid.common.cache.redis
and RedisDAO is in package package com.someproject.prepaid.common.cache.settings
.
java maven spring-boot redis pom.xml
add a comment |
Having worked on a production Spring boot project since almost a year, I am still having a tough time resolving dependencies in a Spring boot project.
Redis read/write is working fine for one module in our project. All I am trying to do, is to implement it in another. I followed the working module.
Following is pom of the working module (where the @Component is defined) -
Module 1's pom -
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.someproject.dependencies</groupId>
<artifactId>someproject-spring-dependencies</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>$project.groupId</groupId>
<artifactId>someproject-common</artifactId>
<version>$project.version</version>
<exclusions>
</dependency>
</dependencies>
In pom of someproject-spring-dependencies -
<redis.clients.jedis.version>2.7.3</redis.clients.jedis.version>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>$jedis.version</version>
</dependency>
And in pom of someproject-common -
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<type>jar</type>
<scope>compile</scope>
</dependency>
I am not sure which of these jedis definitions actually works.
The pom of module 2 is similar to module 1. However, when I try to do the following, in the @Component annotated class of module 2, I get null against object of Autowired RedisDao object, which seems to be a wrapper implementation around the redis.clients package. Trying to give an idea of the same -
- RedisDAOImpl implements RedisDAO. RedisDAOImpl has @Autowired RedisTemplate.
RedisTemplate, another wrapper extends RedisBase. RedisBase implements DisposableBean and has autowired JedisPool, which is within package redis.clients.jedis. RedisTemplate has following call -
Jedis jedis = this.jedisPool.getResource();
Jedis is in package redis.clients.jedis.
- jedisPool is of type JedisPool, annotated as autowired.
- JedisPool is in package package redis.clients.jedis.
Following is the code in the component of module 2, for which the auto wiring seems to be failing -
import com.citruspay.prepaid.common.cache.settings.RedisDAO;
@Component
public class CachedWithdrawalTxnRepository implements CachedWithdrawalTxnDao {
private static final Logger logger = LoggerFactory.getLogger(CachedWithdrawalTxnRepository.class);
@Autowired RedisDAO redis;
@Override
public void create(String uuid)
// TODO Auto-generated method stub
try
redis.setex("withdrawal:"+uuid, 300, "true");
catch(Exception ex)
logger.error(ex.getMessage());
The redis object shows null and I get a null pointer exception.
I am not sure how to debug further.
Update
Answering @Grinish Nepal -
The parent package is being component scanned in the App.java class which is annotated with @SpringBootApplication -
@ComponentScan("com.someproject")
The class where I am Autowiring RedisDAO is in package com.someproject.prepaid.common.cache.redis
and RedisDAO is in package package com.someproject.prepaid.common.cache.settings
.
java maven spring-boot redis pom.xml
is the package where RedisDAO resides being component scanned.??
– Grinish Nepal
Nov 12 '18 at 17:08
Yes, the parent package is being component scanned in the App.java class which is annotated with @SpringBootApplication - @ComponentScan("com.someproject"). The class where I am Autowiring RedisDAO is in package com.someproject.prepaid.common.cache.redis and RedisDAO is in package package com.someproject.prepaid.common.cache.settings.
– Sandeepan Nath
Nov 13 '18 at 6:13
Not sure whats happening here looks like a scan problem to me... Just a thought you can try to component scan redis.clients and see what happens.
– Grinish Nepal
Nov 14 '18 at 15:44
add a comment |
Having worked on a production Spring boot project since almost a year, I am still having a tough time resolving dependencies in a Spring boot project.
Redis read/write is working fine for one module in our project. All I am trying to do, is to implement it in another. I followed the working module.
Following is pom of the working module (where the @Component is defined) -
Module 1's pom -
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.someproject.dependencies</groupId>
<artifactId>someproject-spring-dependencies</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>$project.groupId</groupId>
<artifactId>someproject-common</artifactId>
<version>$project.version</version>
<exclusions>
</dependency>
</dependencies>
In pom of someproject-spring-dependencies -
<redis.clients.jedis.version>2.7.3</redis.clients.jedis.version>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>$jedis.version</version>
</dependency>
And in pom of someproject-common -
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<type>jar</type>
<scope>compile</scope>
</dependency>
I am not sure which of these jedis definitions actually works.
The pom of module 2 is similar to module 1. However, when I try to do the following, in the @Component annotated class of module 2, I get null against object of Autowired RedisDao object, which seems to be a wrapper implementation around the redis.clients package. Trying to give an idea of the same -
- RedisDAOImpl implements RedisDAO. RedisDAOImpl has @Autowired RedisTemplate.
RedisTemplate, another wrapper extends RedisBase. RedisBase implements DisposableBean and has autowired JedisPool, which is within package redis.clients.jedis. RedisTemplate has following call -
Jedis jedis = this.jedisPool.getResource();
Jedis is in package redis.clients.jedis.
- jedisPool is of type JedisPool, annotated as autowired.
- JedisPool is in package package redis.clients.jedis.
Following is the code in the component of module 2, for which the auto wiring seems to be failing -
import com.citruspay.prepaid.common.cache.settings.RedisDAO;
@Component
public class CachedWithdrawalTxnRepository implements CachedWithdrawalTxnDao {
private static final Logger logger = LoggerFactory.getLogger(CachedWithdrawalTxnRepository.class);
@Autowired RedisDAO redis;
@Override
public void create(String uuid)
// TODO Auto-generated method stub
try
redis.setex("withdrawal:"+uuid, 300, "true");
catch(Exception ex)
logger.error(ex.getMessage());
The redis object shows null and I get a null pointer exception.
I am not sure how to debug further.
Update
Answering @Grinish Nepal -
The parent package is being component scanned in the App.java class which is annotated with @SpringBootApplication -
@ComponentScan("com.someproject")
The class where I am Autowiring RedisDAO is in package com.someproject.prepaid.common.cache.redis
and RedisDAO is in package package com.someproject.prepaid.common.cache.settings
.
java maven spring-boot redis pom.xml
Having worked on a production Spring boot project since almost a year, I am still having a tough time resolving dependencies in a Spring boot project.
Redis read/write is working fine for one module in our project. All I am trying to do, is to implement it in another. I followed the working module.
Following is pom of the working module (where the @Component is defined) -
Module 1's pom -
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.someproject.dependencies</groupId>
<artifactId>someproject-spring-dependencies</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>$project.groupId</groupId>
<artifactId>someproject-common</artifactId>
<version>$project.version</version>
<exclusions>
</dependency>
</dependencies>
In pom of someproject-spring-dependencies -
<redis.clients.jedis.version>2.7.3</redis.clients.jedis.version>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>$jedis.version</version>
</dependency>
And in pom of someproject-common -
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<type>jar</type>
<scope>compile</scope>
</dependency>
I am not sure which of these jedis definitions actually works.
The pom of module 2 is similar to module 1. However, when I try to do the following, in the @Component annotated class of module 2, I get null against object of Autowired RedisDao object, which seems to be a wrapper implementation around the redis.clients package. Trying to give an idea of the same -
- RedisDAOImpl implements RedisDAO. RedisDAOImpl has @Autowired RedisTemplate.
RedisTemplate, another wrapper extends RedisBase. RedisBase implements DisposableBean and has autowired JedisPool, which is within package redis.clients.jedis. RedisTemplate has following call -
Jedis jedis = this.jedisPool.getResource();
Jedis is in package redis.clients.jedis.
- jedisPool is of type JedisPool, annotated as autowired.
- JedisPool is in package package redis.clients.jedis.
Following is the code in the component of module 2, for which the auto wiring seems to be failing -
import com.citruspay.prepaid.common.cache.settings.RedisDAO;
@Component
public class CachedWithdrawalTxnRepository implements CachedWithdrawalTxnDao {
private static final Logger logger = LoggerFactory.getLogger(CachedWithdrawalTxnRepository.class);
@Autowired RedisDAO redis;
@Override
public void create(String uuid)
// TODO Auto-generated method stub
try
redis.setex("withdrawal:"+uuid, 300, "true");
catch(Exception ex)
logger.error(ex.getMessage());
The redis object shows null and I get a null pointer exception.
I am not sure how to debug further.
Update
Answering @Grinish Nepal -
The parent package is being component scanned in the App.java class which is annotated with @SpringBootApplication -
@ComponentScan("com.someproject")
The class where I am Autowiring RedisDAO is in package com.someproject.prepaid.common.cache.redis
and RedisDAO is in package package com.someproject.prepaid.common.cache.settings
.
java maven spring-boot redis pom.xml
java maven spring-boot redis pom.xml
edited Nov 13 '18 at 6:26
Sandeepan Nath
asked Nov 12 '18 at 17:00
Sandeepan NathSandeepan Nath
3,492144898
3,492144898
is the package where RedisDAO resides being component scanned.??
– Grinish Nepal
Nov 12 '18 at 17:08
Yes, the parent package is being component scanned in the App.java class which is annotated with @SpringBootApplication - @ComponentScan("com.someproject"). The class where I am Autowiring RedisDAO is in package com.someproject.prepaid.common.cache.redis and RedisDAO is in package package com.someproject.prepaid.common.cache.settings.
– Sandeepan Nath
Nov 13 '18 at 6:13
Not sure whats happening here looks like a scan problem to me... Just a thought you can try to component scan redis.clients and see what happens.
– Grinish Nepal
Nov 14 '18 at 15:44
add a comment |
is the package where RedisDAO resides being component scanned.??
– Grinish Nepal
Nov 12 '18 at 17:08
Yes, the parent package is being component scanned in the App.java class which is annotated with @SpringBootApplication - @ComponentScan("com.someproject"). The class where I am Autowiring RedisDAO is in package com.someproject.prepaid.common.cache.redis and RedisDAO is in package package com.someproject.prepaid.common.cache.settings.
– Sandeepan Nath
Nov 13 '18 at 6:13
Not sure whats happening here looks like a scan problem to me... Just a thought you can try to component scan redis.clients and see what happens.
– Grinish Nepal
Nov 14 '18 at 15:44
is the package where RedisDAO resides being component scanned.??
– Grinish Nepal
Nov 12 '18 at 17:08
is the package where RedisDAO resides being component scanned.??
– Grinish Nepal
Nov 12 '18 at 17:08
Yes, the parent package is being component scanned in the App.java class which is annotated with @SpringBootApplication - @ComponentScan("com.someproject"). The class where I am Autowiring RedisDAO is in package com.someproject.prepaid.common.cache.redis and RedisDAO is in package package com.someproject.prepaid.common.cache.settings.
– Sandeepan Nath
Nov 13 '18 at 6:13
Yes, the parent package is being component scanned in the App.java class which is annotated with @SpringBootApplication - @ComponentScan("com.someproject"). The class where I am Autowiring RedisDAO is in package com.someproject.prepaid.common.cache.redis and RedisDAO is in package package com.someproject.prepaid.common.cache.settings.
– Sandeepan Nath
Nov 13 '18 at 6:13
Not sure whats happening here looks like a scan problem to me... Just a thought you can try to component scan redis.clients and see what happens.
– Grinish Nepal
Nov 14 '18 at 15:44
Not sure whats happening here looks like a scan problem to me... Just a thought you can try to component scan redis.clients and see what happens.
– Grinish Nepal
Nov 14 '18 at 15:44
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53266826%2fredis-dependencies-not-resolving-hence-autowiring-seems-to-be-failing%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53266826%2fredis-dependencies-not-resolving-hence-autowiring-seems-to-be-failing%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
is the package where RedisDAO resides being component scanned.??
– Grinish Nepal
Nov 12 '18 at 17:08
Yes, the parent package is being component scanned in the App.java class which is annotated with @SpringBootApplication - @ComponentScan("com.someproject"). The class where I am Autowiring RedisDAO is in package com.someproject.prepaid.common.cache.redis and RedisDAO is in package package com.someproject.prepaid.common.cache.settings.
– Sandeepan Nath
Nov 13 '18 at 6:13
Not sure whats happening here looks like a scan problem to me... Just a thought you can try to component scan redis.clients and see what happens.
– Grinish Nepal
Nov 14 '18 at 15:44