到目前为止,我已经搜索了整本"The Definitive ANTLR 4 Reference"一书以及许多网站来回答我的问题,但我仍然无法找到关于该主题的任何内容.
我正在使用ANTLR 4来创建一个C语言的子集,它执行一些基本功能.我不知道的是如何在我的Visitor类中实现一个简单的while循环.到目前为止,我的语法中得到了这个:
grammar Expr;
prog: stat+ ;
stat: expr NEWLINE # printExpr
| ID '=' expr NEWLINE # assign
| loop NEWLINE # whileLoop
| relational NEWLINE # relat
| NEWLINE # blank
;
expr: expr op=('*'|'/') expr # MulDiv
| expr op=('+'|'-') expr # AddSub
| INT # int
| ID # id
| '(' expr ')' # parens
;
relational: expr op=(GREATER|LESS) expr # GreaterEqual
;
loop: 'while' '('relational')' NEWLINE? '{'stat*'}' #while
; …Run Code Online (Sandbox Code Playgroud) 大家好 我在使用Springboot时有一个关于将服务自动装配到类中的问题。我在Internet以及Springboot规范中看到的所有示例都具有类似的功能(摘自Springboot 1.5.7版规范):
package com.example.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class DatabaseAccountService implements AccountService {
private final RiskAssessor riskAssessor;
@Autowired
public DatabaseAccountService(RiskAssessor riskAssessor) {
this.riskAssessor = riskAssessor;
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
这是一个通过@Autowiring构造函数通过其构造函数注入属性的类。另一种形式是@Autowire这样的属性:
@Autowired
private final RiskAssessor riskAssessor
Run Code Online (Sandbox Code Playgroud)
但是,在我工作的地方,要使这两种方法都起作用,我被告知我需要使用此方法:
applicationContext.getAutowireCapableBeanFactory().autowireBean(Object.class)
Run Code Online (Sandbox Code Playgroud)
他们告诉我,为了使@Autowired批注起作用,我需要这样做。
现在我对您的问题是:为什么没有简单的注释可以使@Autowire正常运行?(类似于@AutowiredClass)。上面的方法太冗长且难以记住,因此肯定有一种更好的方法可以使@Autowired在类上工作以注入服务,就像我们在Grails中所做的那样(我们刚才说过def someService,它会自动注入)。