java - 部署时 SpringBoot Vaadin 应用程序中没有 Autowiring

标签 java spring vaadin

我有一个带有 Vaadin 的 SpringBoot 应用程序,当使用 mvn clean install spring-boot:run out of 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'.  

这个异常(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)....

我的应用程序类:

@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模块的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

最佳答案

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

关于java - 部署时 SpringBoot Vaadin 应用程序中没有 Autowiring ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44358997/

相关文章:

java - 检索每个文档 Neo4j Lucene 的分数,而不仅仅是顺序

Java单线程CPU使用和多线程CPU使用

java - 为什么 spring boot angularjs gateway 应用程序不能从 ui 应用程序读取?

hibernate - spring 3.1、hibernate 4、tiles2、tomcat 7 - 清理(多次部署导致内存泄漏)

java - 如何在 Vaadin Flow 中使用带有 DataProvider 的自定义组合框过滤?

java - 多线程快速排序没有给出预期的答案

java - 如何使用基于 Java 的配置来配置 Spring Batch StepScope?

java - 将 PopupView 居中? (瓦丁)

google-app-engine - Google 应用引擎的智能 GWT 或 ext GWT 或 Vaadin?

java - 如何在应用程序暂停时更改操作栏的标题文本颜色?