我需要将以下 bean 自动装配到 a List,并且需要List订购我的。这就是我的做法:
@Service
@Order(1)
public class Slave1 implements Slave {}
@Service
@Order(2) //instead of hardcoding I need the value to be picked up externally
public class Slave2 implements Slave {}
@Autowire
List<Slave> slaves;
Run Code Online (Sandbox Code Playgroud)
但我希望从application.properties文件中获取订单值。这可能吗?我可以为@Order属性文件中的注释设置值吗?
即时通讯到本springboot教程,我spring data在我的项目中使用,我试图添加data to database..当我试图这样做时使用以下bt我得到一个错误说
调用方法public abstract java.lang.Object org.springframework.data.repository.CrudRepository.save(java.lang.Object)是无访问器方法!
这是我的代码,
//my controller
@RequestMapping("/mode")
public String showProducts(ModeRepository repository){
Mode m = new Mode();
m.setSeats(2);
repository.save(m); //this is where the error getting from
return "product";
}
//implementing crud with mode repository
@Repository
public interface ModeRepository extends CrudRepository<Mode, Long> {
}
//my mode class
@Entity
@Table(name="mode")
public class Mode implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(unique=true, nullable=false)
private int idMode; …Run Code Online (Sandbox Code Playgroud) 我试图通过使用继承来创建 JPA 实体,我没有使用任何 JPA 多态机制来做到这一点。原因是我希望模型类是独立的,所以如果我想使用 JPA,我可以扩展相同的模型类并创建 JPA 实体并完成工作。我的问题是,这是否可以在不使用 JPA 多态机制的情况下实现,因为当我尝试处理扩展模型类后创建的 JPA 实体时,我看不到从超类继承的属性,但我可以看到新的属性如果我将新属性添加到扩展的 JPA 实体中,则在表中。
这是我的实体:
@Data
public abstract class AtricleEntity {
protected Integer Id;
protected String title;
protected Integer status;
protected String slug;
protected Long views;
protected BigDecimal rating;
protected Date createdAt;
protected Date updatedAt;
}
@Data
@Entity
@Table(name="articles_article")
@RequiredArgsConstructor
public class Article extends AtricleEntity {
public static final String TABLE_NAME = "articles_article";
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer Id;
private String title;
}
@Repository
public interface ArticleRepository extends JpaRepository<Article, …Run Code Online (Sandbox Code Playgroud)