Java 为什么在启动服务器时spring会清空我的数据库表?
我有一个包含96个预定义数据行的数据库表Java 为什么在启动服务器时spring会清空我的数据库表?,java,spring,spring-data,spring-data-jpa,Java,Spring,Spring Data,Spring Data Jpa,我有一个包含96个预定义数据行的数据库表roles,但当我启动服务器(在Tomcat 8.5.28上运行)时,它会清空该表。我想知道为什么会这样 角色控制器 @RestController public class RoleController { private final Logger logger = LoggerFactory.getLogger(RoleController.class); final RoleServiceImpl roleService;
roles
,但当我启动服务器(在Tomcat 8.5.28上运行)时,它会清空该表。我想知道为什么会这样
角色控制器
@RestController
public class RoleController {
private final Logger logger = LoggerFactory.getLogger(RoleController.class);
final RoleServiceImpl roleService;
@Autowired
public RoleController(RoleServiceImpl roleService) {
this.roleService = roleService;
}
@RequestMapping(method = RequestMethod.GET)
public Iterable<Role> getAllRolesByName() {
return roleService.list();
}
}
角色服务impl
@Service
public class RoleServiceImpl implements RoleService {
private final RoleRepository roleRepository;
@Autowired
public RoleServiceImpl(RoleRepository roleRepository) {
this.roleRepository = roleRepository;
}
public Iterable<Role> list() {
return roleRepository.findAll();
}
}
rolerepositional
public interface RoleRepository extends CrudRepository<Role, Integer> {
}
公共接口角色还原扩展了crudepository{
}
我可以在每次启动服务器时加载预定义的96个数据行,但我想知道这是否正常。(即,如果此服务器处于活动状态,我必须关闭它进行维护或类似操作,它会清空表中的所有数据吗?我觉得有点奇怪。)---额外注释--
我正在使用Postgres和Hibernate。我的配置是100%Java。
提前谢谢你 能否检查hibernate属性文件中字段“hibernate.hbm2ddl.auto”的替换值
如果hibernate.hbm2ddl.auto=“创建”或“创建删除”将导致在服务器重新启动期间删除数据。hibernate.hbm2ddl.auto=“创建”或“创建删除”强制数据库重置 这应该是一个评论,女士。。。没有答案。答案需要细节。
public interface RoleService {
}
public interface RoleRepository extends CrudRepository<Role, Integer> {
}