小编Ani*_*hav的帖子

如何在 Hibernate 中启用二级缓存

我的应用程序中需要一些 pojo 对象,所以我想知道如何启用二级缓存。到目前为止默认启用一级缓存,我也想知道二级缓存有哪些优点和缺点。

java orm caching hibernate jpa

6
推荐指数
1
解决办法
3244
查看次数

powermock spring boot中的NoSuchMethodError?

尝试使用PowerMockito Spy在同一个类中模拟私有方法"mapCustomerToRule",但无法获取它.虽然它给出NoSuchMethodError.

但它仍然使私有方法调用,而这又调用另一个thirdPartCall.当thirdPartyCall抛出异常时,我遇到了问题.据我所知,如果我在嘲笑"mapCustomerToRule",它不应该进入方法实现细节并返回模拟响应.

public Map<String, List<Rule>> fetchCutomerToRules() {
        List<ClaimRuleEntity> listOfDHLClaimsRule = dhlClaimRuleRepository.findAllByOrderByRulePriority();

        if (Objects.isNull(listOfDHLClaimsRule) || listOfDHLClaimsRule.isEmpty()) {
            return null;
        }
        log.info("claim rules fetched from database");

        List<ClaimRuleCustomerEntity> listOfDHLClaimRuleCustomerEntity = dhlClaimRuleCustomerRepository.findAllByEnabledFlagTrue();

    if (Objects.isNull(listOfDHLClaimRuleCustomerEntity) || listOfDHLClaimRuleCustomerEntity.isEmpty()) {
        return null;
    }
    log.info("claim customers fetched from database");

    return mapCustomerToRule(listOfDHLClaimsRule, listOfDHLClaimRuleCustomerEntity);
}

private Map<String, List<Rule>> mapCustomerToRule(List<ClaimRuleEntity> listOfDHLClaimsRule,
        List<ClaimRuleCustomerEntity> listOfDHLClaimRuleCustomerEntity) {
    log.info("mapping started for claim rules to customer");
    Map<String, List<Rule>> cutomerToRules = new HashMap<>();

    listOfDHLClaimRuleCustomerEntity.forEach(dhlClaimRuleCustomerEntity -> {

        String customer = dhlClaimRuleCustomerEntity.getCustomer();
        List<Rule> rules = cutomerToRules.get(customer);

        if (Objects.isNull(rules)) …
Run Code Online (Sandbox Code Playgroud)

spring-boot powermockito

5
推荐指数
1
解决办法
5989
查看次数

数据没有被插入到 Spring boot + Spring 数据 JPA 中?

我做了一个spring boot应用程序,在应用程序中我是spring-data-jpa。问题是在数据库中插入数据时,显示数据已插入但数据库中没有数据。以下是我的代码。请让我知道我在哪里做错了。提前致谢。

主类

    package avs.controller;

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.autoconfigure.domain.EntityScan;
    import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

    @SpringBootApplication
    @EntityScan(basePackages = {"avs.pojo"})
    @EnableJpaRepositories(basePackages = {"avs.repository"})
    public class AVS {
        public static void main(String[] args) {
            SpringApplication.run(AVS.class, args);
        }
    }
Run Code Online (Sandbox Code Playgroud)

控制器类

package avs.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import avs.pojo.User;
import avs.repository.UserReposiroty;

@Controller
public class UserController {

    @Autowired
    private UserReposiroty userRepository;

    @RequestMapping(value = "/saveuser", method = RequestMethod.POST)
    @ResponseBody
    @Bean
    public String saveProduct(/*@RequestBody User user*/) {
        User user = new …
Run Code Online (Sandbox Code Playgroud)

spring spring-data-jpa spring-boot

2
推荐指数
1
解决办法
4629
查看次数

javax.validation.ConstraintDefinitionException:Spring MVC中的HV000074

我为我的学生做了一个简单的演示项目,但我无法识别这个错误以下是课程,请告诉我我错过的内容.
接口

package ani.validator;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import javax.validation.Constraint;

@Constraint(validatedBy={CourseCodeContstraintValidator.class})
@Target({ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface CourseCode {

    public String value() default "LUV";

    public String message() default "Not a proper code";

}
Run Code Online (Sandbox Code Playgroud)

自定义验证类

package ani.validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class CourseCodeContstraintValidator implements ConstraintValidator<CourseCode, String> {

    private String prefixCourseCode;

    public void initialize(CourseCode theCourseCode){
         prefixCourseCode = theCourseCode.value();
    }

    public boolean isValid(String value, ConstraintValidatorContext arg1) {

        if(prefixCourseCode != null){
            return value.startsWith(prefixCourseCode);
        }
        return false;
    }
}
Run Code Online (Sandbox Code Playgroud)

欢迎您的建议和意见.提前致谢

spring annotations spring-mvc

2
推荐指数
1
解决办法
1613
查看次数