Vote count:
0
I am writing code with spring boot which will take csv as input and create mongodb collection and insert it to mongodb.
Currently I am sticking in using mongodb in spring boot based code. I am getting NullPointerException while using save method on MongoRepository interface.
Probably this problem is due to incorrect configuration in application.yml file Below is mongodb specific changes in application.yml in src/main/resources directory.
spring:
data:
mongodb.host: localhost
mongodb.port: 27017
mongodb.uri: mongodb://localhost/test
mongo.repositories.enabled: true
Application.java file is below:
@Configuration
@EnableMongoRepositories
@Import(RepositoryRestMvcConfiguration.class)
@EnableAutoConfiguration // Sprint Boot Auto Configuration
@ComponentScan(basePackages = "com.khoubyari.example")
public class Application extends SpringBootServletInitializer {
private static final Class<Application> applicationClass = Application.class;
private static final Logger log = LoggerFactory.getLogger(applicationClass);
public static void main(String[] args) {
SpringApplication.run(applicationClass, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(applicationClass);
}
}
If Application.java implements CommandLineRunner and write mongodb insertion specific code in overrided method run, code is working fine. This code is available in this URL: http://ift.tt/1i9Rhqd
but, my Application.java extends SpringBootServletInitializer class and override configure(SpringApplicationBuilder application) method. Please look at above for my Application.java.
I need to use same db specific code (as in same code for which URL I mentioned above in Application.java class) in utility class existing in different package for my spring boot based project.
Please suggest! If other information is needed, please tell me!
Regards, Shobhit
spring data mongodb configuration in spring boot based project
Aucun commentaire:
Enregistrer un commentaire