Невозможно получить весеннюю загрузку для автоматического создания схемы базы данных в проекте gradle - PullRequest
0 голосов
/ 26 февраля 2020

Я завершил настройку, связанную со всеми БД в файле application.yml, но в журнале не отображается сообщение о создании БД, и при вызове фактического API генерируется ошибка, связанная с таблицей БД.

application.yml

server:
   port: 8080
spring:
   datasource:
      drive-class-name: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://localhost:3306/sys?serverTimezone=UTC&characterEncoding=UTF-8
      username: root
      password: ####
jpa:
   database: mysql
   database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
   general-ddl: true
   show-sql: true
   hibernate:
      format_sql: true
      ddl-auto: create
security:
   oauth:
      authorization:
         check-token-access: isAuthenticated()
   oauth2:
      jwt:
         signkey: 123@#$

Приложение. java:

@EnableAutoConfiguration
@SpringBootApplication
@EnableConfigurationProperties
@EntityScan(basePackages = {"com.springboard.backend"})  
public class Application {

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

}

Пользователи. java

@Getter
@Setter
@Entity
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(of = "uid")
public class Users implements UserDetails {


    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(unique = true)
    private Integer id;

    @Column
    private String username;

    @Column
    private String phonenumber;

    @Column
    private String address;

    @Column
    private String address2;

    public boolean isAddress(String address) {
        return address == "우리집";
    }

    @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
    @JoinColumn(name="user_id")
    @ElementCollection(fetch = FetchType.EAGER)
    private List<UserRole> userRoles = new ArrayList<>();

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.userRoles.stream().map( role -> new  SimpleGrantedAuthority(role.toString())).collect(Collectors.toList());
    }

    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @Override
    public String getUsername() {
        return this.username;
    }

    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @Override
    public boolean isEnabled() {
        return true;
    }

    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @Override
    public String getPassword() {
        return this.phonenumber;
    }

}

UserRole. java

@Data
@Entity
public class UserRole {

    public enum Role {
        ADMIN, USER
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @Column
    @Enumerated(EnumType.STRING)
    private Role rolename;

    public UserRole() {

    }

    public UserRole(Role rolename) {
        this.rolename = rolename;
    }
}

1 Ответ

1 голос
/ 26 февраля 2020

Ваша конфигурация не соответствует действительности. Убедитесь, что jpa меньше spring:

spring:
  jpa:
    database: mysql
    database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
    general-ddl: true
    show-sql: true
    hibernate:
      format_sql: true
      ddl-auto: create
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...