小编Kal*_*mar的帖子

使用Spring注释读取文件属性

我正在尝试学习如何使用spring读取属性文件.在互联网搜索后,我发现我可以使用@value@PropertySource注释来实现这一点.我创建了一个具有以下结构和类代码的项目:

项目结构:

在此输入图像描述

AppConfigMongoDB.java实现:

package com.mongodb.properties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;


@PropertySource("classpath:config/config.properties")
public class AppConfigMongoDB {

@Value("#{mongodb.url}")
private String mongodbUrl;


@Value("#{mongodb.db}")
private String defaultDb;

public String getMongoDb()
{
    return defaultDb;
}

public String getMongoDbUrl()
{
    return mongodbUrl;
}
}
Run Code Online (Sandbox Code Playgroud)

SpringConfiguration.java实现:

 package com.mongodb.properties;

 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;

 @Configuration
 public class SpringConfiguration {
 @Bean
 public AppConfigMongoDB getAppConfigMongoDB(){
        return new AppConfigMongoDB();
  }
 }
Run Code Online (Sandbox Code Playgroud)

Main.java

package com.mongodb.properties;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Main {

public static void main(String[] args) {
    ApplicationContext …
Run Code Online (Sandbox Code Playgroud)

java spring annotations properties

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

USART与STM32f1xx通信

我尝试实现USART通信.所以我将我的STM32f1的RX连接到他的TX.我也为这个沟通写了一个程序.此代码由以下组件组成:

  1. RCC配置
  2. GPIO配置
  3. USART配置
  4. 发送和接收字符串
  5. 发送的字符串和接收的字符串之间的比较
  6. 测试通信是否成功=> LED4亮,否则LED3亮

问题是在所有情况下LED3都会亮起.这意味着数据传输失败.

使用我的IDE(IAR的Embedded Workbench),我编译了这个程序代码:

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "stm32_eval.h"


/* Private typedef -----------------------------------------------------------*/
typedef enum { FAILED = 0, PASSED = !FAILED} TestStatus;

/* Private define ------------------------------------------------------------*/
#define USARTy                   USART1
#define USARTy_GPIO              GPIOA /* PORT name*/
#define USARTy_CLK               RCC_APB2Periph_USART1
#define USARTy_GPIO_CLK          RCC_APB2Periph_GPIOA
#define USARTy_RxPin             GPIO_Pin_10/* pin Rx name*/ 
#define USARTy_TxPin             GPIO_Pin_9 /* pin Tx name*/

#define USARTz                   USART2
#define USARTz_GPIO              GPIOA/* PORT name*/
#define USARTz_CLK               RCC_APB1Periph_USART2
#define USARTz_GPIO_CLK          RCC_APB2Periph_GPIOA
#define USARTz_RxPin …
Run Code Online (Sandbox Code Playgroud)

c stm32

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

libusb 设备描述符:bcdUSB 可能值

我正在使用 libusb-1.0 开发一个 C 应用程序。我想获取一些与USB设备相关的配置参数。我的问题与 bcdUSB 参数有关。我的代码如下:

libusb_device *dev;
struct libusb_device_descriptor desc;

....

ret = libusb_get_device_descriptor(dev, &desc);

if (ret<0) {
    fprintf(stderr, "error in getting device descriptor\n");
    return 1;
}

printf("bcdUSB: %04x\n", desc.bcdUSB);
Run Code Online (Sandbox Code Playgroud)

对于某些设备,我得到 0401 值:

bcdUSB: 0401
Run Code Online (Sandbox Code Playgroud)

我不明白这个值的具体含义是什么。

在libusb代码中,我在libusb_device_descriptor结构代码中找到了这个注释:

/** USB specification release number in binary-coded decimal. A value of
 * 0x0200 indicates USB 2.0, 0x0110 indicates USB 1.1, etc. */
uint16_t bcdUSB;
Run Code Online (Sandbox Code Playgroud)

它仅指定 0200 和 0110 值的含义。是否有包含 0401 在内的 bcdUSB 所有可能值的文档?

c linux usb libusb libusb-1.0

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

c/linux无限循环应用程序:如果调用kill -9命令,则释放内存

我在linux中开发了一个包含无限循环的C应用程序while(1).但是也有一些动态分配的,并且是无限循环下一些有用的指针,所以释放内存的唯一时间是在中断后while(1)通过ctrl-z,ctrl-c,kill -9 apppid,killall appname.所以我的想法是将新的处理程序与内存事件信号解除关联.

void deallocatehandler(int signal){ printf("Memory Deallocation\n"); exit(0);}

int main(){
    signal(SIGINT, &deallocatehandler);
    signal(SIGTSTP, &deallocatehandler);
    signal(SIGKILL, &deallocatehandler);

    while(1){
        /**
        Some code here
        **/
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我按ctrl-c或ctrl-z调用处理程序,但问题出在SIGKILL上.命令kill -9killall没有启动处理程序.

有人知道为什么吗?是否有建议纠正它?

c linux free memory-management sigkill

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

使用fwrite将结构存储在文件中

我想在文件中存储一个结构.我用过这段代码:

#include <stdio.h>
#include <stdlib.h>

typedef struct
{
    int a;
    short b;
    char *ch;
} wrFile;

main()
{
    FILE* fd=fopen("Result.txt","w+");
    wrFile wf={12451,14,"result"};
    fwrite(&wf,sizeof(wrFile),1,fd);
    fclose(fd);
}
Run Code Online (Sandbox Code Playgroud)

我在Result.txt中获得的结果是:

£0^@^@^N^@^@^@^Z^G@^@^@^@^@^@
Run Code Online (Sandbox Code Playgroud)

问题是为什么?

c struct pointers file

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