【发布时间】:2019-06-14 04:46:39
【问题描述】:
请帮忙,我尝试将 Vaadin 放在我的(Spring boot)服务器上,在我设置了一个简单的示例后,我收到以下错误:
无法注册在类路径资源 [com/vaadin/flow/spring/SpringBootAutoConfiguration.class] 中定义的 bean 'dispatcherServletRegistration'。已在类路径资源 [org/springframework/boot/autoconfigure/web/servlet/DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration.class] 中定义了具有该名称的 bean,并且已禁用覆盖。
然后,为了纠正错误,我在 application.prop 中编写: spring.main.allow-bean-definition-overriding=true
并得到以下错误:
org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration 中构造函数的参数 1 需要一个找不到的 'org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath' 类型的 bean。
POM.XML:
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.lopamoko 云液体 0.0.1-快照 罐子
<name>cloudliquid</name>
<description>Demo project for Spring Boot</description>
<pluginRepositories>
<pluginRepository>
<id>maven-annotation-plugin-repo</id>
<url>http://maven-annotation-plugin.googlecode.com/svn/trunk/mavenrepo</url>
</pluginRepository>
</pluginRepositories>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from com.lopamoko.cloudliquid.repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>ru.leon0399</groupId>
<artifactId>dadata</artifactId>
<version>0.8.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-okhttp</artifactId>
<version>9.3.1</version>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-gson</artifactId>
<version>9.3.1</version>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-slf4j</artifactId>
<version>9.3.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry</artifactId>
<version>1.7.16</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>0.7.4</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>6.6.0</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring-boot-starter</artifactId>
</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>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
它是我的主要应用程序:
@SpringBootApplication()
@EntityScan("com/lopamoko/cloudliquid/dataModel")
@EnableJpaRepositories(basePackages = "com.lopamoko.cloudliquid.repository")
public class CloudliquidApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(CloudliquidApplication.class, args);
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
FirebaseConfig firebaseConfig = new FirebaseConfig();
firebaseConfig.configurateFirebaseApplication();
}
@Bean
public DadataService dadataService() {
return new DadataServiceImpl();
}
@Bean
public DadataClient dadataClient() {
return Feign.builder()
.client(new OkHttpClient())
.encoder(new GsonEncoder())
.decoder(new GsonDecoder())
.logger(new Slf4jLogger(DadataClient.class))
.logLevel(Logger.Level.FULL)
.target(DadataClient.class, "https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/address");
}
@Bean
public CustomerDeliveryService customerDeliveryService() {
return new CustomerDeliveryServiceImpl();
}
@Bean
public OrderService orderService() {
return new OrderServiceImpl();
}
@Bean
public YandexService yandexService() {
return new YandexServiceImpl();
}
@Bean
public CategoryService categoryService() {
return new CategoryServiceImpl();
}
@Bean
public ShopService shopService() {
return new ShopServiceImpl();
}
@Bean
public CommentService commentService() {
return new CommentServiceImpl();
}
@Bean
public RatingService ratingService() {
return new RatingServiceImpl();
}
@Bean
public ProductService productService() {
return new ProductServiceImpl();
}
@Bean
public TomcatServletWebServerFactory tomcatFactory() {
return new TomcatServletWebServerFactory() {
@Override
protected void postProcessContext(Context context) {
((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
}
};
})
还有 Vaadin 示例:
@Route("/TestMySelf")
public class MainView extends VerticalLayout {
public MainView() {
Label label = new Label("Hello its CloudLiquid");
}
}
【问题讨论】:
-
对于初学者来说,停止混合 Spring Boot 版本(2.1.1、2.1.0、2.0.1),这肯定会发生麻烦。切勿混合来自不同版本框架的 jar。简而言之,从所有
org.springframework.boot依赖项中删除<version>,这些都由启动器管理。
标签: java spring spring-boot vaadin