Я использую весеннюю загрузку с Cassandra для сохранения данных.Но моя модель БД не могла работать с аннотациями Cassandra.
Я использую Java 11 и Cassandra 3.11.4 для своего веб-сервиса.
class CasDBNode
@ToString
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Table("node")
public class CasDBNode{
@PrimaryKeyColumn(ordinal = 0, name = "id", type = PrimaryKeyType.PARTITIONED)
private String id;
@PrimaryKeyColumn(ordinal = 1, name = "config_id", type = PrimaryKeyType.PARTITIONED)
private String configId;
@Column
private String name;
@Column
private NodeType type;
@Column
private List<? extends NodeResponse> responses;
@Column("parent_node")
private String parentNode;
@Column
private String conditions;
@Column("previous_sibling")
private String previousSibling;
@Column("api_url")
private String apiUrl;
@Column
private List<NodeQuestion> questions;
}
class SimpleNodeQuestion
@ToString
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@UserDefinedType
public class SimpleNodeQuestion implements NodeQuestion {
private String title;
private String output;
@Column("context_name")
private String contextName;
private String condition;
@Column("option_api")
private String optionApi;
@Column("default_options")
private List<Option> defaultOptions;
}
Я видел, как некоторые решения добавляют @UserDefineType должен работать, но я все еще получаю ошибку
Cannot resolve reference to bean 'cassandraTemplate' while setting bean property 'cassandraTemplate';
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cassandraTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'cassandraTemplate' parameter 0;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraSession' defined in class path resource [org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Only primitive types are allowed inside Collections for property [questions] of type ['interface java.util.List'] in entity [com.jamesaq12wsx.IBS_Backend.model.db.CasDBNode]
ОБНОВЛЕНИЕ
После поиска решения я изменяю аннотацию и меняю сообщение об ошибке
класс CasDBNode
@ToString
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Table(value = "node")
public class CasDBNode extends CasDBBaseData implements DBNode{
@PrimaryKeyColumn(ordinal = 0, name = "id", type = PrimaryKeyType.PARTITIONED)
private String id;
@PrimaryKeyColumn(ordinal = 1, name = "config_id", type = PrimaryKeyType.PARTITIONED)
private String configId;
@Column
private String name;
@Column
private NodeType type;
@Column
private List<? extends NodeResponse> responses;
@Column("parent_node")
private String parentNode;
@Column
private String conditions;
@Column("previous_sibling")
private String previousSibling;
@Column("api_url")
private String apiUrl;
@CassandraType(type = DataType.Name.LIST, typeArguments = DataType.Name.UDT, userTypeName = "question")
private List<DBNodeQuestion> questions;
}
класс CasDBNodeQuestion
@UserDefinedType(value = "question")
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class CasDBNodeQuestion implements DBNodeQuestion {
private String title;
private String output;
private String contextName;
private String condition;
private String optionApi;
@CassandraType(type = DataType.Name.LIST, userTypeName = "option")
private List<DBOption> defaultOptions;
}
сообщение об ошибке меняется на
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cassandraTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'cassandraTemplate' parameter 0;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraSession' defined in class path resource [org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.class]: Invocation of init method failed;
nested exception is org.springframework.data.mapping.MappingException: User type [question] not found
обновление
Я изменил interface
на class
и все работает.
Я не уверен, что это проблема, но любая помощь будет принята с благодарностью и заранее!