我的团队正在使用功能分支来实现新功能,并不断将快照构建部署到远程仓库中供我们的用户使用.因此,"部署"实际上只意味着"分发到远程Maven存储库".我们目前只为主分支而不是功能分支运行持续集成构建,原因如下:我们使用Maven构建我们的项目并在JAR旁边分发JavaDoc和源代码.
我的计划现在是为每个功能分支构建添加一个分类器,并期望在创建和部署这样的工件时使用一个分类器:
文物:foo-${version}
.jar,foo-${version}-sources
.jar,foo-${version}-javadoc.jar
分支:特征-X
foo-${version}-feature.jar
,foo-${version}-sources-feature.jar
,foo-${version}-javadoc-feature.jar
我并不真正关心工件的确切命名,我只需要为功能分支单独的main,source和JavaDoc工件.事实证明,JavaDoc插件和源插件都没有考虑配置的分类器,因此有效地覆盖了为我的主构建创建的工件.
我真的不想改变artifactId,虽然这可能会解决问题.你如何处理功能分支和与Maven的持续集成?
continuous-integration feature-branch maven maven-javadoc-plugin maven-source-plugin
我有一个使用Spring Boot Actuator的Java后端,但它不会在Digitalocean Ubuntu VPS上启动.相同的应用程序在我的Mac和其他Ubuntu PC上运行良好.
szabolcs@SmartUpProd:~/smartup$ java -Xmx1536m -jar build/libs/smartup-backend-0.1.0.jar
Run Code Online (Sandbox Code Playgroud)
它开始初始化但每次都停在同一点(没有例外,只是挂起).如果我试图在此时停止它,^C
它将不会使壳返回.
这是outoput:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.1.5.RELEASE) …
Run Code Online (Sandbox Code Playgroud) 我开发了一个MemberRepository
扩展的Spring Data存储库接口org.springframework.data.jpa.repository.JpaRepository
.MemberRepository
有一个方法:
@Cacheable(CacheConfiguration.DATABASE_CACHE_NAME)
Member findByEmail(String email);
Run Code Online (Sandbox Code Playgroud)
结果由Spring缓存抽象缓存(由a支持ConcurrentMapCache
).
我的问题是,我想要写一个集成测试(针对HSQLDB)断言结果被从数据库第一次检索,并从缓存中的第二次.
我最初想过嘲笑jpa基础设施(实体经理等),并以某种方式断言实体经理第二次没有被调用但看起来太难/笨重(参见/sf/answers/1640972021/).
那么有人可以提供有关如何测试带有注释的Spring Data Repository方法的缓存行为的建议@Cacheable
吗?
默认的MappingMongoConverter将自定义类型键("_class")添加到数据库中的每个对象.所以,如果我创建一个Person:
package my.dto;
public class Person {
String name;
public Person(String name) {
this.name = name;
}
}
Run Code Online (Sandbox Code Playgroud)
并将其保存到db:
MongoOperations ops = new MongoTemplate(new Mongo(), "users");
ops.insert(new Person("Joe"));
Run Code Online (Sandbox Code Playgroud)
mongo中的结果对象将是:
{ "_id" : ObjectId("4e2ca049744e664eba9d1e11"), "_class" : "my.dto.Person", "name" : "Joe" }
Run Code Online (Sandbox Code Playgroud)
问题:
将Person类移动到不同的命名空间有什么含义?
是否有可能不用"_class"键污染对象; 没有为Person类编写一个独特的转换器?
我之前没有使用过Spring Data,但是我已经多次使用Hibernate ORM用于基于MySQL的应用程序.我只是不明白为基于MongoDB的应用程序在两者之间选择哪个框架.
我已经尝试寻找答案,但我找不到在生产环境中对两者进行比较的答案.有没有人发现使用MongoDB使用这两个框架有问题?
spring mongodb spring-data spring-data-mongodb hibernate-ogm
我有许多简单的对象类型需要持久化到数据库.我正在使用Spring JPA来管理这种持久性.对于每个对象类型,我需要构建以下内容:
import org.springframework.data.jpa.repository.JpaRepository;
public interface FacilityRepository extends JpaRepository<Facility, Long> {
}
public interface FacilityService {
public Facility create(Facility facility);
}
@Service
public class FacilityServiceImpl implements FacilityService {
@Resource
private FacilityRepository countryRepository;
@Transactional
public Facility create(Facility facility) {
Facility created = facility;
return facilityRepository.save(created);
}
}
Run Code Online (Sandbox Code Playgroud)
我想到有可能用三个基于泛型的类替换每个对象类型的多个类,从而节省了大量的样板编码.我不确定如何去做,事实上如果这是一个好主意?
我正在尝试使用HQL使用JOIN FETCH获取我的实体以及子实体,如果我想要所有结果,这是正常工作但如果我想要一个页面则不是这样
我的实体是
@Entity
@Data
public class VisitEntity {
@Id
@Audited
private long id;
.
.
.
@OneToMany(cascade = CascadeType.ALL,)
private List<VisitCommentEntity> comments;
}
Run Code Online (Sandbox Code Playgroud)
因为我有数百万次访问,我需要使用Pageable,我想在单个数据库查询中获取注释,如:
@Query("SELECT v FROM VisitEntity v LEFT JOIN FETCH v.comments WHERE v.venue.id = :venueId and ..." )
public Page<VisitEntity> getVenueVisits(@Param("venueId") long venueId,...,
Pageable pageable);
Run Code Online (Sandbox Code Playgroud)
该HQL调用抛出以下异常:
Caused by: java.lang.IllegalArgumentException: org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=null,role=com.ro.lib.visit.entity.VisitEntity.comments,tableName=visitdb.visit_comment,tableAlias=comments1_,origin=visitdb.visit visitentit0_,columns={visitentit0_.visit_id ,className=com.ro.lib.visit.entity.VisitCommentEntity}}] …
Run Code Online (Sandbox Code Playgroud) 我有一个简单的存储过程,我用它来测试Spring Data JPA存储过程功能.
create or replace procedure plus1inout (arg in int,res1 out int,res2 out int) is
BEGIN
res1 := arg + 1;
res2 := res1 + 1;
END;
Run Code Online (Sandbox Code Playgroud)
我的代码是:
@Repository
public interface AdjudConverDateSPRepository extends JpaRepository<AdjudConverDateSP, Long> {
@Procedure(name = "plus1")
Object[] plus1(@Param("arg") Integer arg);
}
@Entity
@NamedStoredProcedureQuery(name = "plus1", procedureName = "ADJUD.PLUS1INOUT",
parameters = {
@StoredProcedureParameter(mode = ParameterMode.IN, name = "arg", type = Integer.class),
@StoredProcedureParameter(mode = ParameterMode.OUT, name = "res1", type = Integer.class),
@StoredProcedureParameter(mode = ParameterMode.OUT, name = "res2", type …
Run Code Online (Sandbox Code Playgroud) java stored-procedures hibernate spring-data spring-data-jpa
我怀疑使用Spring将对象注入到类中.我在我的项目中使用了这种代码:
@Resource // or @Autowired even @Inject
private PersonRepository personRepository;
Run Code Online (Sandbox Code Playgroud)
然后在方法上正常使用它:
personRepository.save(p);
Run Code Online (Sandbox Code Playgroud)
否则我在Spring示例中找到了注入构造函数:
private final PersonRepository personRepository;
@Autowired
public PersonController(PersonRepository personRepository) {
this.personRepository = personRepository;
}
Run Code Online (Sandbox Code Playgroud)
那两个都是正确的?或者每个都有它的属性和用法?
是否可以使用Spring Data创建只读存储库?
我有一些实体链接到视图和一些子实体,我想为其提供一些存储库,其中包含一些方法findAll()
,findOne()
以及一些带有@Query
注释的方法.我想避免提供类似的方法save(…)
,delete(…)
因为它们没有任何意义,可能会产生错误.
public interface ContactRepository extends JpaRepository<ContactModel, Integer>, JpaSpecificationExecutor<ContactModel> {
List<ContactModel> findContactByAddress_CityModel_Id(Integer cityId);
List<ContactModel> findContactByAddress_CityModel_Region_Id(Integer regionId);
// ... methods using @Query
// no need to save/flush/delete
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
spring ×7
spring-data ×7
java ×6
jpa ×3
mongodb ×2
hibernate ×1
maven ×1
spring-boot ×1
spring-cache ×1
testing ×1
ubuntu ×1