部署时,SpringBoot Vaadin应用程序中没有自动装配

时间:2017-06-04 21:33:32

标签: java spring vaadin

我有一个带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

1 个答案:

答案 0 :(得分:1)

找到我正在更改现有项目的原因,并且在web.xml中定义了一个vaadin servlet,它在spring boot可以完成其工作之前创建了单例。