-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I'm using ZK 6.5 and trying to load labels from DB using SpringBoot, but the DI does not seem to work inside the LabelLocator (instantiated by a WebAppInit listener)
What is the correct way? This gives NullPointer:
@Slf4j
@Transactional
@Service
class DBLabelLocator implements LabelLocator2 {
@Autowired
LabelService labelService
InputStream locate(Locale locale) {
StringBuilder data = new StringBuilder()
for (MyLabel label : labelService.listAll())
data.append(label.id).append("=").append(label.value).append("\n")
log.info("Labels: \n {}", data.toString())
return new ByteArrayInputStream(data.toString().getBytes(getCharset()))
}
The question is: How do you instantiate the DBLabelLocator inside your WebAppInit?
Annotations don't do anything by themselves. So you need to ask Spring to create the bean for you. E.g. (pseudo code, not tested just highlighting the principle)
in your WebAppInit:
public void init(WebApp wapp) {
// get spring's application context
ApplicationContext ctx = WebApplicationContextUtils
.getRequiredWebApplicationContext(wapp.getServletContext());
// ask for a bean by type
LabelLocator2 dbLabelLocator = ctx.getBean(DBLabelLocator.class);
// register the locator with ZK
Labels.register(dbLabelLocator);
}
if you just say new DBLabelLocator()
spring won't process the annotations @Service
/@Transactional
/@Autowired
. However you forgot to provide that code so my initial guess might just be wrong ... please specify the details if needed.
Asked: 2021-09-16 20:38:57 +0800
Seen: 5 times
Last updated: Sep 17 '21
zk怎么实现动态字段的页面显示,我需要整合一个统计表,而这个统计表的显示字段是动态获取的,这个怎么办
When I used Echarts ,it is report an error
Difference between selenium-support and selenium-java jars
org.zkoss.zk.ui.UiException: You cannot access components belong to other desktop
Upload excel file and then send data in excel file to database oracle using zk framework
How open an url/page passing big data parameters