Skip to content
Snippets Groups Projects
Commit 292c6d62 authored by Bauer Lucca's avatar Bauer Lucca
Browse files

Fix MongoDB Connection

parent fd8688fe
No related branches found
No related tags found
1 merge request!7Dev in Main Merge
package hdm.mi.sthbackend;
import hdm.mi.sthbackend.model.Match;
import hdm.mi.sthbackend.model.Player;
import hdm.mi.sthbackend.repository.IPlayerRepository;
import hdm.mi.sthbackend.repository.ITournamentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.UUID;
import java.util.logging.Logger;
@SpringBootApplication(exclude = {org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class})
......@@ -16,9 +23,27 @@ public class SthBackendApplication {
@Autowired
ITournamentRepository tournamentRepository;
@Autowired
IPlayerRepository playerRepository;
public static void main(String[] args) {
SpringApplication.run(SthBackendApplication.class, args);
}
@Bean
public CommandLineRunner demo() {
return args -> {
// Create SimpleObject instances
Player player = new Player( UUID.randomUUID(), "Name" );
// Insert objects into MongoDB using insert
playerRepository.save( player );
// Retrieve and print all objects from MongoDB
playerRepository.findAll().forEach(System.out::println);
};
}
}
package hdm.mi.sthbackend.repository;
import hdm.mi.sthbackend.model.Player;
import hdm.mi.sthbackend.model.Tournament;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.UUID;
@Repository
public interface IPlayerRepository extends MongoRepository<Player, UUID> {
}
......@@ -5,4 +5,5 @@ spring:
port: 27018
database: tournament-hub
authentication-database: admin
uri: mongodb://alhb:asdasd123@localhost:27018/tournament-hub
username: alhb
password: asdasd123
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment