我正在尝试学习如何使用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) 我尝试实现USART通信.所以我将我的STM32f1的RX连接到他的TX.我也为这个沟通写了一个程序.此代码由以下组件组成:
问题是在所有情况下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) 我正在使用 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 所有可能值的文档?
我在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 -9并killall没有启动处理程序.
有人知道为什么吗?是否有建议纠正它?
我想在文件中存储一个结构.我用过这段代码:
#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 ×4
linux ×2
annotations ×1
file ×1
free ×1
java ×1
libusb ×1
libusb-1.0 ×1
pointers ×1
properties ×1
sigkill ×1
spring ×1
stm32 ×1
struct ×1
usb ×1