小编krz*_*kov的帖子

Lombok @Builder和JPA Default构造函数

我正在使用项目Lombok和Spring Data JPA.有没有办法将Lombok @Builder与JPA默认构造函数连接?

码:

@Entity 
@Builder
class Person {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
}
Run Code Online (Sandbox Code Playgroud)

据我所知,JPA需要默认构造函数,它被@Builder注释覆盖.那有什么解决方法吗?

这段代码给了我错误: org.hibernate.InstantiationException: No default constructor for entity: : app.domain.model.Person

java spring lombok spring-data-jpa

60
推荐指数
6
解决办法
4万
查看次数

在响应正文中返回http 200 OK并出错

我想知道HTTP 200 OK在服务器端发生错误并且响应正文内部出现一些错误时返回是否正确.

例:

  1. 我们正在发送 http GET
  2. 服务器端出现意外情况.
  3. 服务器http 200 OK在响应中返回错误状态代码(例如,{"status":"some error occured"}

是不是正确的行为?我们不应该改变状态代码吗?

http http-status-code-400 http-status-code-200

55
推荐指数
7
解决办法
14万
查看次数

在代码中使用函数时的Eclipse参数对话框/提示

默认情况下在Eclipse中使用函数或创建对象时,它有助于使用如下参数:

Eclipse内容辅助

但一旦完成,它将永远不会再出现.当我将光标指向方法时,有没有办法在已编写的代码上调用此参数助手?

我上传的图像仅在编写代码时出现.

java eclipse

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

Classic C.在execvp函数,stdin和stdout重定向中使用管道

我想使用管道和execvp函数在我的Linux C程序中模拟bash.例如

ls -l | wc -l  
Run Code Online (Sandbox Code Playgroud)

有我的计划:

if(pipe(des_p) == -1) {perror("Failed to create pipe");}

if(fork() == 0) {    //first fork
  close(1);          //closing stdout
  dup(des_p[1]);     //replacing stdout with pipe write 
  close(des_p[0]);   //closing pipe read
  close(des_p[1]);   //closing pipe write

  if(execvp(bash_args[0], bash_args)) // contains ls -l
    /* error checking */
}
else {
  if(fork() == 0) {  //creating 2nd child
    close(0);        //closing stdin
    dup(des_p[0]);   //replacing stdin with pipe read
    close(des_p[1]); //closing pipe write
    close(des_p[0]); //closing pipe read

    if(execvp(bash_args[another_place], bash_args)) //contains wc -l …
Run Code Online (Sandbox Code Playgroud)

c redirect fork execvp

8
推荐指数
1
解决办法
3万
查看次数

openMP和#pragma omp atomic

我有OpenMP的问题.MSVS编译器抛出"pragma omp atomic有不正确的形式".我不知道为什么.代码:(程序使用积分方法指定PI编号)

#include <stdio.h>
#include <time.h>
#include <omp.h>

long long num_steps = 1000000000;
double step;

int main(int argc, char* argv[])
{
    clock_t start, stop;
    double x, pi, sum=0.0;
    int i;
    step = 1./(double)num_steps;
    start = clock();

    #pragma omp parallel for
    for (i=0; i<num_steps; i++)
    { 
        x = (i + .5)*step;
        #pragma omp atomic //this part contains error
        sum = sum + 4.0/(1.+ x*x);  
    }

    pi = sum*step;
    stop = clock();

    // some printf to show results
return …
Run Code Online (Sandbox Code Playgroud)

c++ parallel-processing atomic openmp

8
推荐指数
1
解决办法
3万
查看次数

Spring @Autowired无法连接Jpa存储库

我在这里明显遗漏了什么.我正在制作一个简单的spring boot应用程序,spring data jpa包含内容和面对错误:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [locassa.domain.repository.PersonRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    ... 32 common frames omitted
Run Code Online (Sandbox Code Playgroud)

我的代码:

应用:

@SpringBootApplication
@ComponentScan(basePackages = {"app.controller", "app.domain"})
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}
Run Code Online (Sandbox Code Playgroud)

的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" …
Run Code Online (Sandbox Code Playgroud)

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

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

加载 DLL 期间的 C# 异常。找不到解决办法

我有一个问题,DLL在运行时加载C#.

以下代码:

foreach (var f in Directory.EnumerateFiles(startFolder, "*.dll",            SearchOption.AllDirectories))
{
   try
   {
       var assembly = Assembly.LoadFrom(f);
       var types = assembly.GetTypes(); //exception raised here

       foreach (var type in types)
       {
            if (type.GetInterface("IPlayerFactory") != null)
                 instances.Add((IPlayerFactory)Activator.CreateInstance(type));
       }
       assembly = null;
    }
    catch (ReflectionTypeLoadException ex) { /* later, keep reading  */}
Run Code Online (Sandbox Code Playgroud)

所以例外说:

An exception of type 'System.Reflection.ReflectionTypeLoadException' occurred in
mscorlib.dll but was not handled in user code

Additional information: Unable to load one or more of the requested types. …
Run Code Online (Sandbox Code Playgroud)

c# reflection dll

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

执行功能.有没有办法回到主程序?

我在ubuntu下的exec()函数有问题.有没有可能回到主程序?

例:

printf("Some instructions at beginning\n");
execlp("ls","ls", "-l", NULL);

// i want to continue this program after exec and see the text below
printf("Other instructions\n");
Run Code Online (Sandbox Code Playgroud)

c linux exec

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

访问GPS无法正常工作.应用程序使用网络获取位置

我的应用程序不想使用GPS和使用网络获取位置.我通过分析纬度和经度来检查它们,它们有点随机(如网络位置).

如果我使用另一个使用GPS的应用程序(例如Endomondo Sports tracker),我会看到特征标记,这意味着GPS当前正在工作:

在此输入图像描述

当我启动我的应用程序时,根本就没有标记.

我正在使用以下代码(Lars Vogella的代码,来源:http://www.vogella.com/articles/AndroidLocationAPI/article.html ):

import android.app.Activity;
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class ShowLocationActivity extends Activity implements LocationListener {
  private TextView latituteField;
  private TextView longitudeField;
  private LocationManager locationManager;
  private String provider;


/** Called when the activity is first created. */

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    latituteField = (TextView) findViewById(R.id.TextView02);
    longitudeField = (TextView) findViewById(R.id.TextView04);

    // Get the location manager
    locationManager = …
Run Code Online (Sandbox Code Playgroud)

gps android location locationmanager location-provider

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

Spock setupSpec() 中的 @Autowired 变量访问

我需要在测试启动时执行一次代码块Spock。我无法使用@Autowiredin setupSpec()which is default 方法进行此类初始化,但是@Bean直到那时 s 才会被加载。

在网络上找到(可追溯到 2015 年)来源

该行为是 Spring 的 TestContext 框架设计的结果。我看不出有什么办法可以在不遇到其他问题的情况下改变它。将 TestContext 框架与 JUnit 结合使用时,情况没有任何不同。

已经六年了,有什么干净的方法可以做到这一点吗?我想省略肮脏的解决方法

java spring spring-test spock

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