2017-06-04 84 views
0

我有一個Vaadin應用SpringBoot與MVN開始全新安裝彈簧開機時正常工作:用完的IDE。
如果部署到Tomcat服務器@Autowire(對於ViewProvider)不起作用。不能使用自動裝配在SpringBoot Vaadin應用部署時

我得到以下警告:

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

發現我改變現有項目的原因,並有在web.xml中定義一個vaadin servlet,它創造了單春啓動之前可以做的工作。