Update the web configuration to add the db manager and a repository.

main
KKlochko 1 year ago
parent 05528396ac
commit b202457f10

@ -4,6 +4,7 @@ import java.sql.Timestamp;
import java.util.List;
import java.util.UUID;
import jakarta.persistence.EntityManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@ -11,6 +12,8 @@ import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import space.kklochko.spring_rest_example.db.factories.EntityManagerConnection;
import space.kklochko.spring_rest_example.db.repositories.IndicatorRepository;
import space.kklochko.spring_rest_example.models.Indicator;
@EnableWebMvc
@ -22,11 +25,13 @@ public class WebConfig implements WebMvcConfigurer {
converters.add(new MappingJackson2HttpMessageConverter());
}
@Bean("indicator")
public Indicator getIndicator() {
UUID id = UUID.fromString("becbafac-702c-11ee-9113-c0e4349366ab");
Timestamp timestamp = Timestamp.valueOf("2023-10-18 14:30:00");
Indicator indicator = new Indicator(id, "Blood2", "Fine2", timestamp);
return indicator;
@Bean
public EntityManager manager() {
return (new EntityManagerConnection("spring_rest_example")).connect();
}
@Bean
public IndicatorRepository indicatorRepository(EntityManager manager) {
return new IndicatorRepository(manager);
}
}

Loading…
Cancel
Save