小编en *_*ris的帖子

表'DBNAME.hibernate_sequence'不存在

我有一个使用spring data/jpa的SpringBoot 2.0.1.RELEASE应用程序

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

但是当我在Amazon Aurora数据库中进行更新时,我收到此错误:

2018-04-13 09:20 [pool-1-thread-1]错误ohid.enhanced.TableStructure.execute(148) - 无法读取hi值com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:表'elbar sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)中不存在.hibernate_sequence'

我在要保存的实体中有这个

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
Run Code Online (Sandbox Code Playgroud)

我想避免在DB中获取ID的任何缺点.

java mysql spring spring-data spring-boot

20
推荐指数
5
解决办法
2万
查看次数

Spring Boot 2. Hikari连接池优化

我有一个SpringBoot应用程序,我正在控制器中进行一些性能测试,我意识到无论我把控制器放在第一个查询,它需要多年的时间与其他人相比......(这是一个远程连接,但我不能改变这个)

long t1 = System.nanoTime();

menuPriceSummaryService.findAllVegan().stream();            

long t2 = System.nanoTime();
long elapsedTimeInSeconds = (t2 - t1) / 1000000000;
System.out.println("elapsedTimeInSeconds1 -> " +  elapsedTimeInSeconds);

t1 = System.nanoTime();

menuPriceSummaryService.findAllVegan();

t2 = System.nanoTime();
elapsedTimeInSeconds = (t2 - t1) / 1000000000;
System.out.println("elapsedTimeInSeconds2 -> " +  elapsedTimeInSeconds);

t1 = System.nanoTime();
menuPriceSummaryService.findAllVegan().parallelStream();
t2 = System.nanoTime();
elapsedTimeInSeconds = (t2 - t1) / 1000000000;
System.out.println("elapsedTimeInSeconds3 -> " +  elapsedTimeInSeconds);

t1 = System.nanoTime();
menuPriceSummaryService.findAllVegan().parallelStream().filter(this::notInMyFavourites);
t2 = System.nanoTime();
elapsedTimeInSeconds = (t2 - t1) / 1000000000;
Run Code Online (Sandbox Code Playgroud)

时间:

elapsedTimeInSeconds1 -> 76
elapsedTimeInSeconds2 …
Run Code Online (Sandbox Code Playgroud)

authentication spring jdbc spring-boot hikaricp

7
推荐指数
1
解决办法
1774
查看次数

邮递员:设置环境变量

我在 Postman 中有一个 POST 调用,它返回这个 JSON 对象:

{
    "token": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiO3Jsb3Blei5hbnRvbmlvODVAZ21haWwuY29tIiwiZXhwIjoxNTkzNjc0MzUxLCJpYXQiOjE1MzMxOTQzNTF9.oTPVkcgF1QcoOsg6KDGOaaTyCQYrWS51QDdRn__MDigivcsuaqUgBhDaTYwQnxOtOCjxDRXO_cqK8i5xBq02bQ"
}
Run Code Online (Sandbox Code Playgroud)

在我的环境中,我设置了一个名为 token

我想设置值。我试过

var data = JSON.parse(responseBody);
postman.setEnvironmentVariable("token", data.message.token);
Run Code Online (Sandbox Code Playgroud)

var data = pm.response.json();
pm.environment.set("token", data.message.token);
Run Code Online (Sandbox Code Playgroud)

但两者都有错误:SyntaxError | 无效或意外的令牌

rest restful-authentication http-post restful-architecture postman

7
推荐指数
1
解决办法
7004
查看次数

在 IntelliJ IDEA 中运行单个 Junit 测试

我是 IntelliJ IDEA 的新手,我想像在 Eclipse 中一样执行一个 Junit 测试,但我还没有看到这个选项

在此处输入图片说明

java eclipse junit intellij-idea junit4

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

验证方法公共抽象java.util.List的查询失败

我有一个基本的SpringBoot应用程序。使用Spring Initializer,JPA,嵌入式Tomcat,Thymeleaf模板引擎并将其打包为可执行JAR文件。SpringBoot的版本是2.0.1.RELEASE。我已经使用此方法创建了一个从CrudRepository扩展的类存储库

@Query("select us.priceAlertsTapas.tapa from User us left join us.priceAlertsTapas  pat left join pat.tapa tapa where pat.priceAlert = ?1")
    List<Tapa> tapasByUserPriceAlert (PriceAlert pa);
Run Code Online (Sandbox Code Playgroud)

但是当我初始化项目时,我得到了这个错误:

Validation failed for query for method public abstract java.util.List



    at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:93)
    at org.springframework.data.jpa.repository.query.SimpleJpaQuery.<init>(SimpleJpaQuery.java:63)
    at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromMethodWithQueryString(JpaQueryFactory.java:76)
    at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromQueryAnnotation(JpaQueryFactory.java:56)
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$DeclaredQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:139)
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:206)
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:79)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lookupQuery(RepositoryFactorySupport.java:553)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$mapMethodsToQuery$1(RepositoryFactorySupport.java:546)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.Iterator.forEachRemaining(Iterator.java:116)
    at java.util.Collections$UnmodifiableCollection$1.forEachRemaining(Collections.java:1049)
    at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.mapMethodsToQuery(RepositoryFactorySupport.java:548)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$new$0(RepositoryFactorySupport.java:538)
    at java.util.Optional.map(Optional.java:215)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:538)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:317)
    at …
Run Code Online (Sandbox Code Playgroud)

java spring-mvc spring-data spring-data-jpa spring-boot

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

Java8 lambda:按相反的顺序对流进行排序?

我有这个列表,我想按保留顺序订购,但我没有.reversed()在自动完成辅助中找到任何功能

 myMenus(user)
                .stream()
                .filter(mps ->  mps.get1PercentageChange() > 0 &&
                                mps.get2PercentageChange() > 0 &&
                                mps.get3PercentageChange() > 0 &
                                mps.get4PercentageChange() > 0)
                .sorted(comparing(mps -> mps.getDailyPercentageChange()))
                .collect(toList());
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

myMenus(user)
        .stream()
        .filter(mps ->  mps.get1PercentageChange() > 0 &&
                        mps.get2PercentageChange() > 0 &&
                        mps.get3PercentageChange() > 0 &
                        mps.get4PercentageChange() > 0)
        .sorted(comparing(mps -> mps.getDailyPercentageChange()).reversed())
        .collect(toList());
Run Code Online (Sandbox Code Playgroud)

但后来我有编译错误:

Cannot infer type argument(s) for <T, U> comparing(Function<? super T,? 
     extends U>)
Run Code Online (Sandbox Code Playgroud)

collections lambda functional-programming java-8 java-stream

5
推荐指数
2
解决办法
2761
查看次数

CrudRepository 不删除具有关系的对象

我有一个基本的 SpringBoot 应用程序。使用 Spring Initializer、JPA、嵌入式 Tomcat、Thymeleaf 模板引擎,并打包为可执行 JAR 文件。我创建了这个 Repository 类:

@Repository
public interface MenuRepository extends CrudRepository<Menu, Long> {
..
}
Run Code Online (Sandbox Code Playgroud)

和这个服务类

@Service
@Transactional(readOnly = true)
public class MenuService {

     @Autowired
     protected MenuRepository menuRepository;

     @Transactional
     public void delete (Menu menu) {
         menuRepository.delete  (menu);
     }
     ..
}
Run Code Online (Sandbox Code Playgroud)

和这个 Junit 测试:

@ContextConfiguration(classes={TestSystemConfig.class})
@RunWith(SpringRunner.class)
@SpringBootTest(classes = MenuGestApplication.class) 
public class MenuServiceTests {
...
@Test
    public void testDelete () {

        Menu menu = new menu(); 
        menu.setmenuId("bacalla-amb-tomaquet");
        menuService.save(menu);

        MenuPrice menuPrice = new menuPrice(menu);
        menuPrice.setPrice((float)20.0);
        menuPriceService.save(menuPrice);

        MenuPriceSummary …
Run Code Online (Sandbox Code Playgroud)

java junit spring-mvc junit4 spring-boot

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

无法使用 SpringBoot 延迟初始化角色集合

我有一个基本的 SpringBoot 2.0.3.RELEASE 应用程序,它使用 Spring Initializer、JPA、嵌入式 Tomcat、Thymeleaf 模板引擎和包作为可执行 JAR 文件,在 pom.xml 中有这些依赖项。

我有一个名为 Company 的域对象:

@Entity
@Table(name="t_company")
public class Company implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public Company() {
    }



    /**
     * @param companyName
     */ 
    public Company(String companyName) {
        super();
        this.name = companyName;
    }



    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @NotEmpty
    @Length(max = 100)
    private String name;


    @OneToMany(mappedBy = "company", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private Set<User> users = new HashSet<>(); …
Run Code Online (Sandbox Code Playgroud)

junit hibernate spring-mvc spring-data-jpa spring-boot

5
推荐指数
2
解决办法
6947
查看次数

SpringBoot 中的 javax.validation.constraints.Email

我有一个经过此验证的 bean:

@Email(message = "Email is not valid", regexp="{(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])}")
@NotEmpty(message = "Email cannot be empty")
private String email;
Run Code Online (Sandbox Code Playgroud)

当电子邮件为空时,消息很好,但是当我输入此文本时

perisava.util.Random@1d7f0036
Run Code Online (Sandbox Code Playgroud)

没有显示错误

java email spring email-validation spring-boot

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

Spring 5.0.7.RELEASE 中的模拟静态方法

我有一个 Spring 5.0.7.RELEASE 应用程序,带有一些 WebLayer 测试,我在我的应用程序中进行了此测试:

@RunWith(SpringRunner.class)
@WebAppConfiguration
public class HongoControllerTest  {


    @Autowired
    private WebApplicationContext wac;

    private MockMvc mockMvc;



    @Before
    public void setup() {

        mockStatic(TranslationUtils.class);
}
Run Code Online (Sandbox Code Playgroud)

但是当我运行测试时出现以下错误:

org.mockito.exceptions.base.MockitoException: 
The used MockMaker SubclassByteBuddyMockMaker does not support the creation of static mocks

Mockito's inline mock maker supports static mocks based on the Instrumentation API.
You can simply enable this mock mode, by placing the 'mockito-inline' artifact where you are currently using 'mockito-core'.
Note that Mockito's inline mock maker is not supported on …
Run Code Online (Sandbox Code Playgroud)

java junit spring mocking spring-boot

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