[英]Vaadin + Spring Integration: Null Pointer exception
I have a Vaadin web application with UI class like this: 我有一个带有UI类的Vaadin Web应用程序,如下所示:
@SuppressWarnings("serial")
@Theme("mytheme")
public class LogsUI extends UI {
LogsView logsViewer = new LogsView();
@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = LogsUI.class)
public static class Servlet extends VaadinServlet {
}
@Override
protected void init(VaadinRequest request) {
Panel panel = new Panel();
panel.setContent(logsViewer);
panel.setSizeFull();
setContent(panel);
}
}
As u can see i add use setContent
to add LogsView class which is a view - it is a fragment of declaration: 如您所见,我添加了使用
setContent
添加LogsView类的视图-它是声明的片段:
@SuppressWarnings("serial")
public class LogsView extends CustomComponent implements View {
//some variables, buttons, components etc
ProcessDao processDao;
//sample method
void sampleMethod(){
processDao = new ProcesDao;
processDao.getAllprocesses(); //just sample, no matter about logic
}
}
My ProcessDao
class: 我的
ProcessDao
类:
public class ProcessDao {
@Autowired
ApplicationConfiguration applicationConfiguration;
public ProcessDao() {
}
public List<ProcessEntity> getAllProcess(){
System.out.println("TEST:" + applicationConfiguration);
//entity manager and other stuffs
return processList;
}
}
As u can see i did System.out.println()
to check if im getting applicationConfiguration
object. 如您所见,我做了
System.out.println()
来检查是否正在获取applicationConfiguration
对象。 Im getting null. 我越来越空了。 This is main problem.
这是主要问题。
this is my ApplicationConfiguration class: 这是我的ApplicationConfiguration类:
@Configuration
@EnableTransactionManagement
@ComponentScan(basePackages = {"com.sample.project"})
@PropertySource({"classpath:jpa.postgresql.properties", "classpath:hibernate.properties"})
@EnableJpaRepositories(basePackages = {"com.sample.project.repo"})
public class ApplicationConfiguration extends WebMvcConfigurerAdapter {
@Value("${javax.persistence.jdbc.driver}")
private String driverClassName;
@Value("${javax.persistence.jdbc.url}")
private String databaseUrl;
@Value("${javax.persistence.jdbc.user}")
private String databaseUser;
@Value("${javax.persistence.jdbc.password}")
private String databasePassword;
@Value("${hibernate.dialect}")
private String dialect;
@Value("${hibernate.show_sql}")
private boolean showSQL;
@Value("${hibernate.hbm2ddl.auto}")
private String hbm2ddlAuto;
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
@Bean
@PersistenceContext
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource(dataSource());
entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class);
entityManagerFactoryBean.setJpaProperties(hibernateJPAProperties());
entityManagerFactoryBean.setPackagesToScan("com.sample.project");
return entityManagerFactoryBean;
}
@Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(driverClassName);
dataSource.setUrl(databaseUrl);
dataSource.setUsername(databaseUser);
dataSource.setPassword(databasePassword);
return dataSource;
}
public Properties hibernateJPAProperties() {
Properties properties = new Properties();
properties.put("hibernate.dialect", dialect);
properties.put("hibernate.show_sql", showSQL);
properties.put("hibernate.hbm2ddl.auto", hbm2ddlAuto);
return properties;
}
@Bean
public JpaTransactionManager transactionManager() {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
return transactionManager;
}
@Bean
public FinancialProcessEntityDao financialProcessEntityDao() {
FinancialProcessEntityDao dao = new FinancialProcessEntityDao();
return dao;
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
Am i something missing? 我缺少什么吗? How to properly integrate my Vaadin app with Spring?
如何将我的Vaadin应用程序与Spring正确集成?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.