这是我第一次问问题,所以请指导我克服我可能犯的任何错误。
我正在使用Intellij,以及Spring和Gradle --这也是第一次--来制作Web应用程序的后端部分。
它编译正常,但一旦我尝试运行它,我得到以下错误:
2018-02-27 17:00:33.526 INFO 4308 --- [ main] g.n.e.s.k.KidspirationApplication : Starting KidspirationApplication on mini-me with PID 4308 (started by Orestis in C:\Users\Orestis\Desktop\Software Technology\Stack-Over-Flowers\kidspiration)
2018-02-27 17:00:33.531 INFO 4308 --- [ main] g.n.e.s.k.KidspirationApplication : No active profile set, falling back to default profiles: default
2018-02-27 17:00:33.606 INFO 4308 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@551bdc27: startup date [Tue Feb 27 17:00:33 EET 2018]; root of context hierarchy
2018-02-27 17:00:33.969 WARN 4308 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [gr.ntua.ece.softeng.kidspiration.KidspirationApplication]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'registerController' for bean class [gr.ntua.ece.softeng.kidspiration.Register_Login.RegisterController] conflicts with existing, non-compatible bean definition of same name and class [gr.ntua.ece.softeng.kidspiration.Controllers.RegisterController]
2018-02-27 17:00:34.136 ERROR 4308 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [gr.ntua.ece.softeng.kidspiration.KidspirationApplication]; nested exception is
org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'registerController' for bean class [gr.ntua.ece.softeng.kidspiration.Register_Login.RegisterController] conflicts with existing, non-compatible bean definition of same name and class [gr.ntua.ece.softeng.kidspiration.Controllers.RegisterController]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:181) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:308) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:272) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:92) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at gr.ntua.ece.softeng.kidspiration.KidspirationApplication.main(KidspirationApplication.java:14) [classes/:na]
Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'registerController' for bean class [gr.ntua.ece.softeng.kidspiration.Register_Login.RegisterController] conflicts with existing, non-compatible bean definition of same name and class [gr.ntua.ece.softeng.kidspiration.Controllers.RegisterController]
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.checkCandidate(ClassPathBeanDefinitionScanner.java:345) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:283) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:135) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:287) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:198) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:167) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
... 13 common frames omitted
Process finished with exit code 1
内部版本等级为:
buildscript {
ext {
springBootVersion = '1.5.10.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin:'idea'
apply plugin: 'org.springframework.boot'
group = 'gr.ntua.ece.softeng'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
jar {
baseName = 'kidspiration-platform'
version = '0.1.0'
}
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework:spring-jdbc')
compile('mysql:mysql-connector-java')
compile('com.h2database:h2')
//runtime('mysql:mysql-connector-java')
}
ApplicationConfig.java:
package gr.ntua.ece.softeng.kidspiration.Configuration;
import org.springframework.beans.factory.annotation.Autowired;
import javax.sql.DataSource;
//import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.*;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@EnableTransactionManagement
@ComponentScan(basePackages = "gr.ntua.ece.softeng.kidspiration")
@PropertySource(value = {"classpath:application.properties"})
//@EnableAutoConfiguration
public class ApplicationConfig {
@Autowired
private Environment env;
@Bean
public DataSource datasource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(env.getRequiredProperty("spring.datasource.driver-class-name"));
dataSource.setUrl(env.getRequiredProperty("spring.datasource.url"));
dataSource.setUsername(env.getRequiredProperty("spring.datasource.username"));
dataSource.setPassword(env.getRequiredProperty("spring.datasource.password"));
return dataSource;
}
@Bean
public JdbcTemplate jdbcTemplate(DataSource dataSource) {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
jdbcTemplate.setResultsMapCaseInsensitive(true);
return jdbcTemplate;
}
@Bean
public PlatformTransactionManager txManager() {
return new DataSourceTransactionManager(datasource()); //check later if datasource could be passed as parameter
}
}
应用程序. Java是:
package gr.ntua.ece.softeng.kidspiration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableScheduling
public class KidspirationApplication {
public static void main(String[] args) {
SpringApplication.run(KidspirationApplication.class, args);
}
}
到目前为止,我还没有设法找出导致错误消息的特定代码部分,并且源代码被扩展了。
所以,如果你想看到它的一部分或全部,我将非常感谢你建议一个简单的方法来介绍它!
我试过重命名“registerController”,但它只会导致错误消息中的一个小改动。
请告诉我,如果我解释得不够清楚或细节太少。
任何形式的帮助或建议将不胜感激。
1条答案
按热度按时间ajsxfq5m1#
从配置文件中删除您的组件扫描。由于它已滚动到
SpringBootApplication
注解中,因此不需要它。https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/autoconfigure/SpringBootApplication.html
您也可以删除
@PropertySource(value = {"classpath:application.properties"})
Spring Boot 将自动加载此。有关https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config详细信息,请访问www.example.com。