我有一个带有Vaadin的SpringBoot应用程序,它在使用mvn clean install spring-boot启动时工作正常:用完IDE。 如果将其部署到Tomcat服务器,则@Autowire(对于ViewProvider)不起作用。
我得到以下警告:
o.s.c.a. ConfigurationClassPostProcessor : Cannot enhance @Configuration bean definition 'com.vaadin.spring.VaadinConfiguration' since its singleton instance has been created too early. The typical cause is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor return type: Consider declaring such methods as 'static'.这个例外:
java.lang.IllegalArgumentException: Cannot add a null view provider at com.vaadin.navigator.Navigator.addProvider(Navigator.java:887) ~[vaadin-server-7.7.7.jar.7.7.7] at com.example.gui.MainUI.init(ManinUI.java:39)....我的应用课程:
@SpringBootApplication(scanBasePackages = { "com.example" }) @EnableJpaRepositories(basePackages={"com.example.db"}) @EntityScan(basePackages={"com.example.db.entities"}) @PropertySources(value = {@PropertySource("classpath:db.properties"), @PropertySource("classpath:gui.properties")} ) @EnableVaadin public class PersonApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(PersonApplication.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(PersonApplication.class); } }我的UI类:
@Theme("valo") @SpringUI(path="/swme") public class MainUI extends UI { private Navigator navigator; private SpringViewProvider viewProvider; @Autowired public void setViewProvider(SpringViewProvider viewProvider) { this.viewProvider = viewProvider; } @Autowired private PersonService myService; @Override protected void init(VaadinRequest request) { navigator = new Navigator(this, this); navigator.addProvider(viewProvider); final VerticalLayout layout = new VerticalLayout(); layout.setMargin(true); setContent(layout); layout.addComponent(new MyView(myService)); } }父母pom:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>DOTS4</artifactId> <version>5.0</version> <packaging>pom</packaging> <modules> <module>database</module> <module>service</module> <module>gui</module> </modules> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <java.version>1.8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <junit.version>4.12</junit.version> </properties> <build> <pluginManagement> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> <configuration> <classifier>exec</classifier> </configuration> </execution> </executions> </plugin> </plugins> </pluginManagement> </build> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> </dependency> </dependencies> </project>gui modul的pom:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>gui</artifactId> <packaging>war</packaging> <parent> <groupId>com.example</groupId> <artifactId>DOTS4</artifactId> <version>1.0</version> </parent> <properties> <war.name>myapp</war.name> <maven-war-plugin.version>3.1.0</maven-war-plugin.version> <vaadin.version>7.7.7</vaadin.version> <vaadin-spring.version>1.2.0</vaadin-spring.version><!-- v2 requires vaadin.version >=8.0--> </properties> <build> <finalName>${war.name}</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>${maven-war-plugin.version}</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> </manifest> </archive> </configuration> </plugin> <plugin> <groupId>com.vaadin</groupId> <artifactId>vaadin-maven-plugin</artifactId> <version>${vaadin.version}</version> <configuration> <extraJvmArgs>-Xmx512M -Xss8M</extraJvmArgs> <webappDirectory>target/classes/VAADIN/widgetsets</webappDirectory> <draftCompile>false</draftCompile> <compileReport>false</compileReport> <style>OBF</style> <strict>true</strict> </configuration> <executions> <execution> <goals> <goal>clean</goal> <goal>resources</goal> <goal>update-widgetset</goal> <goal>compile</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>com.example</groupId> <artifactId>database</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>com.example</groupId> <artifactId>service</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>com.vaadin</groupId> <artifactId>vaadin-spring-boot-starter</artifactId> <version>${vaadin-spring.version}</version> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>com.vaadin</groupId> <artifactId>vaadin-bom</artifactId> <version>${vaadin.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> </project>我正在使用Vaadin v7.7.7和VaadinSpring v1.2以及Tomcat-8.5.15
I have a SpringBoot application with Vaadin which works fine when started with mvn clean install spring-boot:run out of the IDE. If it is deployed to a Tomcat server @Autowire (for the ViewProvider) doesn’t work.
I get the following Warning:
o.s.c.a. ConfigurationClassPostProcessor : Cannot enhance @Configuration bean definition 'com.vaadin.spring.VaadinConfiguration' since its singleton instance has been created too early. The typical cause is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor return type: Consider declaring such methods as 'static'.And this exception:
java.lang.IllegalArgumentException: Cannot add a null view provider at com.vaadin.navigator.Navigator.addProvider(Navigator.java:887) ~[vaadin-server-7.7.7.jar.7.7.7] at com.example.gui.MainUI.init(ManinUI.java:39)....My Applicaton Class:
@SpringBootApplication(scanBasePackages = { "com.example" }) @EnableJpaRepositories(basePackages={"com.example.db"}) @EntityScan(basePackages={"com.example.db.entities"}) @PropertySources(value = {@PropertySource("classpath:db.properties"), @PropertySource("classpath:gui.properties")} ) @EnableVaadin public class PersonApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(PersonApplication.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(PersonApplication.class); } }My UI class:
@Theme("valo") @SpringUI(path="/swme") public class MainUI extends UI { private Navigator navigator; private SpringViewProvider viewProvider; @Autowired public void setViewProvider(SpringViewProvider viewProvider) { this.viewProvider = viewProvider; } @Autowired private PersonService myService; @Override protected void init(VaadinRequest request) { navigator = new Navigator(this, this); navigator.addProvider(viewProvider); final VerticalLayout layout = new VerticalLayout(); layout.setMargin(true); setContent(layout); layout.addComponent(new MyView(myService)); } }The parent pom:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>DOTS4</artifactId> <version>5.0</version> <packaging>pom</packaging> <modules> <module>database</module> <module>service</module> <module>gui</module> </modules> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <java.version>1.8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <junit.version>4.12</junit.version> </properties> <build> <pluginManagement> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> <configuration> <classifier>exec</classifier> </configuration> </execution> </executions> </plugin> </plugins> </pluginManagement> </build> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> </dependency> </dependencies> </project>The pom of the gui modul:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>gui</artifactId> <packaging>war</packaging> <parent> <groupId>com.example</groupId> <artifactId>DOTS4</artifactId> <version>1.0</version> </parent> <properties> <war.name>myapp</war.name> <maven-war-plugin.version>3.1.0</maven-war-plugin.version> <vaadin.version>7.7.7</vaadin.version> <vaadin-spring.version>1.2.0</vaadin-spring.version><!-- v2 requires vaadin.version >=8.0--> </properties> <build> <finalName>${war.name}</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>${maven-war-plugin.version}</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> </manifest> </archive> </configuration> </plugin> <plugin> <groupId>com.vaadin</groupId> <artifactId>vaadin-maven-plugin</artifactId> <version>${vaadin.version}</version> <configuration> <extraJvmArgs>-Xmx512M -Xss8M</extraJvmArgs> <webappDirectory>target/classes/VAADIN/widgetsets</webappDirectory> <draftCompile>false</draftCompile> <compileReport>false</compileReport> <style>OBF</style> <strict>true</strict> </configuration> <executions> <execution> <goals> <goal>clean</goal> <goal>resources</goal> <goal>update-widgetset</goal> <goal>compile</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>com.example</groupId> <artifactId>database</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>com.example</groupId> <artifactId>service</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>com.vaadin</groupId> <artifactId>vaadin-spring-boot-starter</artifactId> <version>${vaadin-spring.version}</version> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>com.vaadin</groupId> <artifactId>vaadin-bom</artifactId> <version>${vaadin.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> </project>I am using Vaadin v7.7.7 with VaadinSpring v1.2 and Tomcat-8.5.15
最满意答案
找到了我正在更改现有项目的原因,并且在web.xml中定义了一个vaadin servlet,它在spring boot可以完成其工作之前创建了单例。
Found the reason I was changing an existing project and there was a vaadin servlet defined in web.xml, which created the singleton before spring boot could do its work.
更多推荐
发布评论