会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132489个问题
Python 全系列/第十八阶段:数据分析-数据可视化/matplotlib 22351楼
JAVA 全系列/第十一阶段:分布式RPC调用和分布式文件存储/Zookeeper 22352楼
JAVA 全系列/(旧的隐藏)第二十一阶段:百战商城项目(Spring Cloud最新架构)/百战商城项目 22353楼
JAVA 全系列/第五阶段:JavaWeb开发/Ajax技术详解(旧) 22354楼
JAVA 全系列/(旧的隐藏)第二十一阶段:百战商城项目(Spring Cloud最新架构)/百战商城项目 22355楼
Python 全系列/ 第十四阶段:自动化操作办公软件、邮件、定时任务等/自动化操作办公软件、邮件、定时任务等 22356楼
JAVA 全系列/第十八阶段:亿级高并发电商项目_架构/编码(旧)/电商:完成CMS系统 22357楼

#coding=UTF-8

from threading import Thread, Event
from time import sleep
from random import randint


def door():
    global state
    while True:
        if even.is_set():#如果even事件为真,则执行
            print('我是门:门开着,可以通行~')
            sleep(1)
        else:
            print('我是门:门关了~请刷卡!')
            state = 0#门已关闭,开门循环重置为0
            even.wait()#even事件为等待,进程暂停
        if state > 3:#state在3次循环后
            print('我是门:超过3 秒,门自动关门')
            even.clear() #even事件为假,所有even.wait()发挥作用,将进程暂停
        state +=1#循环一次,state+1,控制门开启时间
        sleep(1)#线程暂停1秒,控制循环时间
def person():
    global state
    n = 0#人员编号
    while True:
        if even.is_set():
            print('我是人:门开着:{}号进入'.format(n))
        else:
            even.set()#将even事件标记为真
            state = 0#开门循环重置为0
            print('我是人:门关着,{}号人刷卡进门'.format(n))
        n += 1
        sleep(randint(1, 10))#随机1-10米秒来一个人,模拟刷卡
if __name__ == '__main__':
    state = 0
    even = Event()
    even.set()
    d = Thread(target=door)
    d.start()
    p = Thread(target=person)
    p.start()

老师,在执行的时候应该先提示

我是门:门关了~请刷卡!

但是我的这个程序,直接就是开着门的,请帮忙看看问题在哪里,谢谢

图片.png

Python 全系列/第三阶段:Python 网络与并发编程/并发编程 22358楼


加上@Value("${msg}")之后启动报错


logback.rar

image.png


2021-04-19 13:28:18.145 [main] INFO  com.bjsxt.logback.LogbackApplication - Starting LogbackApplication using Java 1.8.0_131 on LY with PID 17640 (D:\demo\springBoot\logback\target\classes started by yu lin in D:\demo\springBoot\logback)

2021-04-19 13:28:18.150 [main] INFO  com.bjsxt.logback.LogbackApplication - No active profile set, falling back to default profiles: default

2021-04-19 13:28:19.303 [main] INFO  o.s.boot.web.embedded.tomcat.TomcatWebServer - Tomcat initialized with port(s): 8080 (http)

2021-04-19 13:28:19.312 [main] INFO  org.apache.coyote.http11.Http11NioProtocol - Initializing ProtocolHandler ["http-nio-8080"]

2021-04-19 13:28:19.313 [main] INFO  org.apache.catalina.core.StandardService - Starting service [Tomcat]

2021-04-19 13:28:19.313 [main] INFO  org.apache.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/9.0.45]

2021-04-19 13:28:19.469 [main] INFO  o.a.c.core.ContainerBase.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext

2021-04-19 13:28:19.469 [main] INFO  o.s.b.w.s.c.ServletWebServerApplicationContext - Root WebApplicationContext: initialization completed in 1249 ms

2021-04-19 13:28:19.523 [main] WARN  o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'helloController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'msg' in value "${msg}"

2021-04-19 13:28:19.526 [main] INFO  org.apache.catalina.core.StandardService - Stopping service [Tomcat]

2021-04-19 13:28:19.540 [main] INFO  o.s.b.a.l.ConditionEvaluationReportLoggingListener - 


Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

2021-04-19 13:28:19.565 [main] ERROR org.springframework.boot.SpringApplication - Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'helloController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'msg' in value "${msg}"

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:405)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1413)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:601)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524)

at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)

at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144)

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:782)

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:774)

at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:339)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1340)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1329)

at com.bjsxt.logback.LogbackApplication.main(LogbackApplication.java:10)

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'msg' in value "${msg}"

at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:178)

at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124)

at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:239)

at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210)

at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties$0(PropertySourcesPlaceholderConfigurer.java:175)

at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:936)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1321)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300)

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:657)

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)

at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)

... 18 common frames omitted


Process finished with exit code 1


JAVA 全系列/第九阶段:Spring Boot实战/Spring Boot 22359楼
JAVA 全系列/第一阶段:JAVA 快速入门/变量、数据类型、运算符 22361楼
Python 全系列/第二十阶段:数据分析-统计分析/Python统计分析 22363楼
JAVA 全系列/第十九阶段:Spring Cloud微服务技术栈/Spring Cloud(旧) 22364楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637