@KaizerSX

Как в intellig idea community edition прописать настройки application.properties?

Добрый день!

Подключил через Maven Spring Boot, JPA. Создал необходмые классы, сущности и контроллер. Без подключения БД Spring Boot работает отлично, но , когда пытаюсь подключить к проекту данные из БД не понимаю как заставить IDEA принимать настройки из application.properties. Дело в том, что настройки светятся как серые , типо не используются. Почитал, что в Community Edition нельзя через application.properties прописать настройки. Может кто подскажет альтернативные способы? А то обидно, Spring Boot работает, а с БД работать не могу.

spring.h2.console.enabled=true

spring.datasource.url=jdbc:h2:./SalesPointscds
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=user
spring.datasource.password=pass

spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect


CONTROLLER:

package RestExample.MainPack.Controller;

import RestExample.MainPack.model.SALESPOINTDO;
import RestExample.MainPack.repos.SalesPointRepos;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GreetingController {

    @Autowired
    SalesPointRepos salesPointRepos;


    @GetMapping("/greeting")
    @ResponseBody
    public String greeting() {


        Iterable<SALESPOINTDO> allSP=salesPointRepos.findAll();

        StringBuilder sb= new StringBuilder();

        allSP.forEach(sp->sb.append(sp+"<br>"));


        return  sb.toString();
    }
}


ENTITY:

package RestExample.MainPack.model;

import javax.persistence.*;

@Entity
@Table(name = "SALESPOINTDO")
public class SALESPOINTDO {

 @Id
 @GeneratedValue(strategy = GenerationType.AUTO)
 private Integer ID;

 @Column(name = "NAME")
 private String name;

 @Column(name = "CITY")
 private String city;

 @Column(name = "ADDRESS")
 private String address;

    public SALESPOINTDO() {
    }

    public Integer getID() {
        return ID;
    }

    public void setID(Integer ID) {
        this.ID = ID;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Override
    public String toString() {
        return "City: "+getCity()+" "+"Address: "+getAddress();
    }
}


РЕПОЗИТОРИЙ:


package RestExample.MainPack.repos;

import RestExample.MainPack.model.SALESPOINTDO;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;


@Repository
public interface SalesPointRepos extends CrudRepository<SALESPOINTDO,Integer> {





}


STARTSPRINGBOOT:

package RestExample.MainPack;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;



@SpringBootApplication
public class StartRest {

    public static void main(String[] args) {
        SpringApplication.run(StartRest.class, args);



    }
}


Скрин из БД:
5e3281a312ba7609794864.png
  • Вопрос задан
  • 1780 просмотров
Пригласить эксперта
Ответы на вопрос 1
KaizerSX файл в
src\main\resources\application.properties?

открывается как
Properties properties = new Properties();
		InputStream input = null;
		try {
			input = <имя вашего класса>.class.getClassLoader()
					.getResourceAsStream("application.properties");
			properties .load(input);

      
          System.err.println(properties .getProperty("spring.h2.console.enabled"));

что печатает ?
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы