这是我的应用程序:
public static void main( String[] args ) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
//run the importer
final ImportNewOrders importer = (ImportNewOrders) ApplicationContextProvider.getApplicationContext().getBean("importNewOrders");
importer.run();
//importer.runInBackground();
}
Run Code Online (Sandbox Code Playgroud)
这是我的配置:
@Configuration
@ComponentScan(basePackages = {
"com.production"
})
@PropertySource(value = {
"classpath:/application.properties",
"classpath:/environment-${MY_ENVIRONMENT}.properties"
})
@EnableJpaRepositories("com.fettergroup.production.repositories")
@EnableTransactionManagement
public class Config {
.... skipping things that aren't relevant
@Bean
public ImportNewOrders importNewOrders() {
return new ImportNewOrders();
}
Run Code Online (Sandbox Code Playgroud)
这是我的班级......
@Component
public class ImportNewOrders implements Task {
private final static Logger logger = Logger.getLogger(ImportNewOrders.class.getName());
@Autowired
private OrderService orderService;
@Autowired …Run Code Online (Sandbox Code Playgroud) 我在我的实体定义中使用doctrine注释来定义每个变量行为,即:
@ORM\Column(type="string", length=50, nullable=false)
Run Code Online (Sandbox Code Playgroud)
如果我提交表单,将该字段留空,则通过验证,但是(对于corse)我收到有关INSERT语句的错误,因为他无法插入NULL值.这怎么可能?
我想知道我的代码有什么问题,因为当我尝试测试我的代码时,我什么也得不到.
public class SeleniumTest {
private WebDriver driver;
private String nome;
private String idade;
@FindBy(id = "j_idt5:nome")
private WebElement inputNome;
@FindBy(id = "j_idt5:idade")
private WebElement inputIdade;
@BeforeClass
public void criarDriver() throws InterruptedException {
driver = new FirefoxDriver();
driver.get("http://localhost:8080/SeleniumWeb/index.xhtml");
PageFactory.initElements(driver, this);
}
@Test(priority = 0)
public void digitarTexto() {
inputNome.sendKeys("Diego");
inputIdade.sendKeys("29");
}
@Test(priority = 1)
public void verificaPreenchimento() {
nome = inputNome.getAttribute("value");
assertTrue(nome.length() > 0);
idade = inputIdade.getAttribute("value");
assertTrue(idade.length() > 0);
}
@AfterClass
public void fecharDriver() {
driver.close();
}
Run Code Online (Sandbox Code Playgroud)
}
我正在使用 …
我正在尝试使用@Scheduled功能.我已经按照这个和本教程,但我不能让我的计划任务被执行.
我创造了一个工人:
@Component("syncWorker")
public class SyncedEliWorker implements Worker {
protected Logger logger = Logger.getLogger(this.getClass());
public void work() {
String threadName = Thread.currentThread().getName();
logger.debug(" " + threadName + " has began to do scheduled scrap with id=marketwatch2");
}
}
Run Code Online (Sandbox Code Playgroud)
和SchedulingService:
@Service
public class SchedulingService {
protected Logger logger = Logger.getLogger(this.getClass());
@Autowired
@Qualifier("syncWorker")
private Worker worker;
@Scheduled(fixedDelay = 5000)
public void doSchedule() {
logger.debug("Start schedule");
worker.work();
logger.debug("End schedule");
}
}
Run Code Online (Sandbox Code Playgroud)
并尝试在我的applicationcontext中进行不同的布线.最终版本如下:
<beans xmlns=...
xmlns:task="http://www.springframework.org/schema/task"
...
xsi:schemaLocation=" ..
http://www.springframework.org/schema/task …Run Code Online (Sandbox Code Playgroud) //我的工厂课
@Component
public class UserRewardAccountValidatorFactory {
@Autowired
private VirginAmericaValidator virginAmericaValidator;
private static class SingletonHolder {
static UserRewardAccountValidatorFactory instance = new UserRewardAccountValidatorFactory();
}
public static UserRewardAccountValidatorFactory getInstance() {
return SingletonHolder.instance;
}
private UserRewardAccountValidatorFactory() {}
public PartnerValidator getPartnerValidator(Partner partner){
return virginAmericaValidator;
}
}
Run Code Online (Sandbox Code Playgroud)
//我的Validator类
@Service
public class VirginAmericaValidator implements PartnerValidator {
@Override
public void validate(String code) throws InvalidCodeException{
//do some processing if processing fails throw exception
if (code.equals("bad".toString())){
throw new InvalidCodeException();
}
}
}
Run Code Online (Sandbox Code Playgroud)
//用法:
PartnerValidator pv = UserRewardAccountValidatorFactory.getInstance().getPartnerValidator(partner);
if (pv != …Run Code Online (Sandbox Code Playgroud) 我有2个不同的按钮,可以在一个mapview中触发一组不同的注释.我有一些淡出按钮的动作方法,在这一点上应该出现一个注释,但是我无法弄清楚如何在注释方法中说"如果激活了这个动作,那么从这个类加载注释".所以这是我目前的代码
- (void)queryForAllPostsNearLocation:(CLLocation *)currentLocation withNearbyDistance:(CLLocationAccuracy)nearbyDistance {
if (????? IBAction 1 is activated ?????) {
NSString *button1 = @"Today";
}
if (????? IBAction 2 is activated ?????) {
NSString *button1 = @"Tomorrow";
}
PFQuery *query = [PFQuery queryWithClassName:button1];
Run Code Online (Sandbox Code Playgroud)
我希望我能正确地传达我的问题,有人可以帮助我.
我的java应用程序使用Spring构造型注释(@Controller,@ Component)和autowire注释来管理依赖注入.
它不是Web应用程序,只是简单的jar.它也是基于纯注释的代码,即根本没有xml.
什么是从main方法初始化基于Spring注释的应用程序上下文和默认配置的正确方法?
我写了3个类"PrintDevice,Printer,Test"如下
首先,PrintDevice.java
public @interface PrintDevice{
String defaultPrint();
int defaultNumber();
}
Run Code Online (Sandbox Code Playgroud)
第二,Printer.java
@PrintDevice(defaultPrint="print",defaultNumber=5)
public class Printer{
public Printer(){
//empty Construcutor
}
@PrintDevice(defaultPrint="print",defaultNumber=5)
public void print(int number){
System.out.println(number);
}
}
Run Code Online (Sandbox Code Playgroud)
第三,Test.java
import java.lang.reflect.*;
public class Test{
public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException{
Printer printer = new Printer();
PrintDevice anno = printer.getClass().getAnnotation(PrintDevice.class);
Method m = printer.getClass().getMethod(anno.defaultPrint(),int.class);
m.invoke(printer,anno.defaultNumber());
}
}
Run Code Online (Sandbox Code Playgroud)
并且没有任何问题地编译它们,但是当我尝试运行Test.java时,我得到NullPointerExcetion如下: -
Test.main中线程"main"java.lang.NullPointerException中的异常(Test.java:7)
为什么我的场景中的第二个测试在行The value for annotation attribute SuppressWarnings.value must be an array initializer上有语法错误SuppressWarnings?
public class AnnotationTest {
private static final String supUnused = "unused";
private static final String supDeprecation = "deprecation";
private static final String[] suppressArray = { "unused", "deprecation" };
public static void main(String[] args) {
// Test 1
@SuppressWarnings( { supUnused, supDeprecation } )
int a = new Date().getDay();
// Test 2
@SuppressWarnings(suppressArray) // syntax error
int b = new Date().getDay();
}
}
Run Code Online (Sandbox Code Playgroud)
如果您将参数作为两个单一常量传递,则可以正常工作.
如果您使用数组常量传递它,则会出现语法错误.
这个错误的解释是什么?
从PEP 3107,http: //www.python.org/dev/peps/pep-3107/#parameters,我刚刚注意到一些我不了解并且不太了解的功能注释的额外语法.
def foo(a: expression, b: expression = 5):
...
Run Code Online (Sandbox Code Playgroud)
这是我不确定的第二部分,expression = 5.你会如何在实际意义上使用它?当然不要指定默认参数,这已经是不言而喻的了.
annotations ×10
java ×4
spring ×4
arrays ×1
autowired ×1
doctrine-orm ×1
findby ×1
forms ×1
ibaction ×1
if-statement ×1
ios ×1
python ×1
reflection ×1
spring-mvc ×1
string ×1
symfony ×1
testng ×1
validation ×1