小编Nas*_*din的帖子

Spring Boot中的JPA存储库"没有类型的限定bean"

我正在使用Spring Boot实现Rest API.由于我的实体类来自另一个包的包,我必须使用注释指定它EntityScan.此外,我曾经EnableJpaRepositories指定了定义JPA存储库的包.这是我的项目的样子:

在此输入图像描述

//Application.java

@Configuration
@EnableAutoConfiguration
@ComponentScan
@EntityScan("org.mdacc.rists.cghub.model")
@EnableJpaRepositories("org.mdacc.rists.cghub.ws.repository") 
Run Code Online (Sandbox Code Playgroud)

在我的控制器类中,我有一个自动装配的SeqService对象.

//SeqController.java

@Autowired private SeqService seqService;

@RequestMapping(value = "/api/seqs", method = GET, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<List<SeqTb>> getSeqs() {
    List<SeqTb> seqs = seqService.findAll();
    return new ResponseEntity<List<SeqTb>>(seqs, HttpStatus.OK);
}
Run Code Online (Sandbox Code Playgroud)

SeqService是一个接口,我从中创建了一个Bean类SeqServiceBean.在SeqServiceBeanI中自动安装了JPA存储库:

// SeqServiceBean.java

@Autowired private SeqRepository seqRepository;

@Override
public List<SeqTb> findAll() {
    List<SeqTb> seqs = seqRepository.findAll();
    return seqs;
}

//SeqRepository.java

@Repository
public interface SeqRepository extends JpaRepository<SeqTb, Integer> {

    @Override
    public List<SeqTb> findAll();

    public SeqTb …
Run Code Online (Sandbox Code Playgroud)

java spring jpa spring-data spring-boot

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

是否需要web.xml来部署Spring引导应用程序

我试图将弹簧启动应用程序打包为战争.根据这个,我修改了应用程序类:

@SpringBootApplication
@EntityScan({"org.mdacc.rists.cghub.model"}) 
@EnableJpaRepositories(basePackages = {"org.mdacc.rists.cghub.ws.repository"})
public class Application extends SpringBootServletInitializer
{

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

    @Override
     protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
         return application.sources(Application.class);
     }
}
Run Code Online (Sandbox Code Playgroud)

还在我的pom.xml中添加了以下内容

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

当我打包项目时,我收到以下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project cg-web: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
Run Code Online (Sandbox Code Playgroud)

当我阅读spring boot应用程序时,我从未见过有关创建web.xml的任何内容.将Spring启动应用程序部署为战争需要web.xml吗?

java web-services war spring-boot

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

如何复制文件并授予它们目标目录的权限

我正在将文件从源复制到位置.源不属于我,源文件的权限是---- rwx ---.处理我所拥有的目标目录的文件的权限是---- rx ---.目标目录的权限是drwxrwsrwx.如何使用目标目录具有相同权限的文件.我试过"cp --no-preserve = all"但它没有用(仍然是相同的权限).

linux deployment permissions cp

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

如何在单个语句中定义多个变量

在Python中,我可以在一行中定义两个带有数组的变量.

>>>[a,b] = [1,2]
>>>a
1
>>>b
2
Run Code Online (Sandbox Code Playgroud)

我如何用Java做同样的事情?

我在PCT类中有几个变量,类型是最终的.有没有办法像Python一样在一行中定义它们?以下格式显然不适用于Java.我可以单独定义它们,但它会调用parseFile方法两次,我想避免.

public class PCT {
    final int start;
    final int stop;
    public PCT (File file) {
        //......
        //......
        // the following statement does not compile
        [start, stop] = parseFile(file);
    }
    public int[] parseFile(File f) {
        int[] aa = new int[2];
        // ....
        // ....
        return aa;
    }
}
Run Code Online (Sandbox Code Playgroud)

java arrays

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

os.killpg 寻找什么 PID

我正在编写代码来杀死一个进程和所有子进程。

根据这篇文章,可以使用以下命令杀死同一进程组中的所有子进程os.killpg(pro.pid, signal.SIGTERM)

在测试期间,我手动启动了这个进程,它产生了 5 个子进程。

    UID      PID  PPID  C STIME TTY          TIME CMD
    ddd    25066 19475  0 Nov03 ?        00:00:00 /bin/sh -c gtdownload -c ~/.cghub.key --max-children 4 -vv -d https://cghub.ucsc.edu/cghub/data/analysis/download/ab0e89b4-5310-11e4-88da-adc9fc308db6 2
    ddd    25067 25066  0 Nov03 ?        00:00:07 /rsrch1/rists/djiao/apps/cghub/libexec/gtdownload -c /rsrch1/rists/djiao/.cghub.key --max-children 4 -vv -d https://cghub.ucsc.edu/cghub/data/analysis/d
    ddd    25073 25067  0 Nov03 ?        00:00:18 /rsrch1/rists/djiao/apps/cghub/libexec/gtdownload -c /rsrch1/rists/djiao/.cghub.key --max-children 4 -vv -d https://cghub.ucsc.edu/cghub/data/analysis/d
    ddd    25077 25067  0 Nov03 ?        00:00:18 /rsrch1/rists/djiao/apps/cghub/libexec/gtdownload -c /rsrch1/rists/djiao/.cghub.key --max-children 4 -vv -d https://cghub.ucsc.edu/cghub/data/analysis/d …
Run Code Online (Sandbox Code Playgroud)

python subprocess

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

如何通过布尔列过滤火花数据帧

我创建了一个具有以下架构的数据框:

In [43]: yelp_df.printSchema()
root
 |-- business_id: string (nullable = true)
 |-- cool: integer (nullable = true)
 |-- date: string (nullable = true)
 |-- funny: integer (nullable = true)
 |-- id: string (nullable = true)
 |-- stars: integer (nullable = true)
 |-- text: string (nullable = true)
 |-- type: string (nullable = true)
 |-- useful: integer (nullable = true)
 |-- user_id: string (nullable = true)
 |-- name: string (nullable = true)
 |-- full_address: string (nullable = true)
 |-- latitude: double …
Run Code Online (Sandbox Code Playgroud)

python filter apache-spark spark-dataframe

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

在 LDAP 身份验证中使用正确凭据的未分类异常

我想使用 Spring Boot 为 Web 应用程序实现 LDAP 身份验证。这是我的WebSecurityConfig课程:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .anyRequest()
                .authenticated()
                .and()
            .formLogin();
    }

    @Configuration
    protected static class AuthenticationConfiguration extends
            GlobalAuthenticationConfigurerAdapter {

        @Override
        public void init(AuthenticationManagerBuilder auth) throws Exception {
            auth
                .ldapAuthentication()
                    .userDnPatterns("cn={0},ou=institution,ou=people")
                    .contextSource()
                    .url("ldap://ldap.mdanderson.edu:389/dc=mdanderson,dc=edu");
        }
    }   
}
Run Code Online (Sandbox Code Playgroud)

我用我的凭据测试了它。以下是 LDAP 服务器上我的用户信息的屏幕截图:

在此输入图像描述

在登录页面上,如果我输入 djiao 作为我的用户名和错误的密码,它会显示Bad credentials。但是如果我给出正确的密码,我会得到 500:

There was an unexpected error (type=Internal Server Error, status=500).
Uncategorized exception occured during …
Run Code Online (Sandbox Code Playgroud)

java authentication ldap spring-security

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

为什么我用 spring-boot 得到 404 来休息

我正在使用 Spring Boot 实现休息服务。实体类在单独的包中定义。所以我在Application.java中添加了Component注解。

@Configuration
@EnableAutoConfiguration
@ComponentScan("org.mdacc.rists.cghub.model")
@EnableJpaRepositories(basePackages = "org.mdacc.rists.cghub.model") 
public class Application 
{
    public static void main( String[] args )
    {
        SpringApplication.run(Application.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的控制器类:

// SeqController.java
@RestController
public class SeqController {

    @Autowired
    private SeqService seqService;
    @RequestMapping(
            value = "/api/seqs", 
            method = RequestMethod.GET, 
            produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<List<SeqTb>> getSeqs() {
        List<SeqTb> seqs = seqService.findAll();

        return new ResponseEntity<List<SeqTb>>(seqs, HttpStatus.OK);
    }
}
Run Code Online (Sandbox Code Playgroud)

我还创建了一个 JPA 数据存储库,它扩展了 JPARepository,我在其中添加了自定义查询代码。

// SeqRepository.java
@Repository
public interface SeqRepository extends JpaRepository<SeqTb, Integer> {

    @Override
    public List<SeqTb> findAll(); …
Run Code Online (Sandbox Code Playgroud)

java rest spring-data-jpa spring-boot

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

ldapsearch:凭据无效

我正在尝试使用命令对我们的机构 LDAP 服务器进行身份验证ldapsearch。我在 LDAP 中的用户信息如下图所示1]

我在下面使用此命令按我的 DN 进行搜索:

ldapsearch -x -H ldap://ldap.mdanderson.edu:389 -D "CN=Djiao,OU=Institution,OU=People" -b DC=mdanderson,DC=edu -w xxxyyyzzz
Run Code Online (Sandbox Code Playgroud)

但是我得到了错误:

ldap_bind: Invalid credentials (49)
    additional info: 80090308: LdapErr: DSID-0C0903A9, comment: AcceptSecurityContext error, data 52e, v1db1
Run Code Online (Sandbox Code Playgroud)

我的 ldapsearch 命令有什么问题?

authentication ldap

4
推荐指数
2
解决办法
3万
查看次数

我的 python 代码中必须有 main 函数吗?

我可以编写一个带有一堆函数但没有 main 函数的 python 代码吗?该脚本的目的是让其他脚本从中导入一些函数。我将其称为 setvar_general.py 或将由一系列其他 setvar_x 脚本导入的名称。虽然这些 setvar_x 执行更具体的操作,但 setvar_general 除了提供构建块之外不执行任何操作。因此不需要在setvar_general.py中定义main函数。

我想这一切都归结为“我必须有主要功能”这个问题吗?

python program-entry-point

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

Rest api 对 GET 请求返回空括号

我用 Spring Boot 实现了 Rest api。在我的控制器类中,我有代码来处理 GET 请求,如果找到记录,该请求将返回 JSON。

// SeqController.java
@Autowired
private SeqService seqService;
@RequestMapping( 
        value = "/api/seqs/{analysis_id}", 
        method = RequestMethod.GET, 
        produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<SeqTb>> getSeqByAnalysisId(@PathVariable("analysis_id") String analysis_id) {
    List<SeqTb> seqs = seqService.findByAnalysisId(analysis_id);
    return new ResponseEntity(seqs, HttpStatus.OK);
}
Run Code Online (Sandbox Code Playgroud)

我还创建了一个SeqServiceBean扩展接口的 bean 类SeqService,该接口又调用以下 JPA 存储库中的方法进行查询。

//SeqRepository.java
@Repository
public interface SeqRepository extends JpaRepository<SeqTb, Integer> {

    @Override
    public List<SeqTb> findAll();

    public List<SeqTb> findByAnalysisId(String analysisId);
}
Run Code Online (Sandbox Code Playgroud)

问题是当我在浏览器中输入网址(http://localhost:8080/api/seqs/fdebfd6e-d046-4192-8b97-ac9f65dc2009)时,它只返回一对空括号。我刚刚查了一下数据库,确实有这条记录。我做错了什么?

rest json spring-data-jpa spring-boot

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

用于Spring LDAP身份验证的登录名

我创建了一个本地LDAP服务器,并添加了密码为"123456"的用户"djiao" 在此输入图像描述

尝试使用Spring Boot实现Spring Security的身份验证.我的webconfig类如下:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .anyRequest()
                .authenticated()
                .and()
            .formLogin();
    }

    @Bean
    public ActiveDirectoryLdapAuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
        ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider("", "ldap://localhost:10389");
        provider.setConvertSubErrorCodesToExceptions(true);
        provider.setConvertSubErrorCodesToExceptions(true);
        provider.setUseAuthenticationRequestCredentials(true);
        return provider;
    }

    @Bean
    public LoggerListener loggerListener() {
        return new LoggerListener();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(activeDirectoryLdapAuthenticationProvider());
    }
Run Code Online (Sandbox Code Playgroud)

但是我似乎无法从登录页面登录.

  1. 如果我使用djiao(cn)或djiao1(uid),我会得到500.

    [LDAP:错误代码34 - 给出错误的DN:djiao1(0x64 0x6A 0x69 0x61 0x6F 0x31)无效]; 嵌套异常是javax.naming.InvalidNameException:[LDAP:错误代码34 - 给出不正确的DN:djiao1(0x64 0x6A 0x69 0x61 0x6F …

ldap spring-security spring-boot

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

如何制作父项的spring boot项目子模块

我想在这个父项目下创建两个模块(dao和api).模块api将使用Spring Boot来恢复api.由于spring boot项目都有spring-boot-starter-parent作为父模块,如何在另一个父模块下创建子模块?我的理解是Java项目只能有一个父项.

java rest spring-boot

0
推荐指数
1
解决办法
1953
查看次数