Java 无法分析配置类Spring
这是我第一次问问题,所以请引导我克服我可能犯的任何错误 我正在使用Intellij、Spring和Gradle——也是第一次——来制作web应用程序的后端部分。Java 无法分析配置类Spring,java,spring,spring-boot,gradle,Java,Spring,Spring Boot,Gradle,这是我第一次问问题,所以请引导我克服我可能犯的任何错误 我正在使用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
它编译正常,但一旦我尝试运行它,就会出现以下错误:
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')
}
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
}
}
build.gradle是:
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')
}
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
}
}
ApplicationConfig.java是:
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')
}
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
}
}
Application.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”,但它只会导致错误消息中的一个小改动 请告诉我,我是不是解释得不够公正,还是说得太少。
任何形式的帮助或建议都将不胜感激。从配置文件中删除组件扫描。它不需要,因为它被滚动到
SpringBootApplication
注释中
您还可以删除@PropertySource(value={“classpath:application.properties”})
spring boot将自动加载此文件
有关这方面的更多信息,请参阅 此外,错误消息显示:注释为bean类指定了bean名称'registerController'[gr.ntua.ece.softing.kidspiration.>>Register\u Login.Register controllerhello O.Kariotis.欢迎来到stackoverflow。我是否可以建议您在帖子中添加错误消息、java源代码和build.gradle作为文本而不是图像。这使其他人更容易理解您的问题(以四个空格或一个制表符开头的段落格式为代码)。祝您好运,找到您需要的帮助。我希望在stackoverflow这里看到您的更多问题和答案。非常感谢您的建议。我将立即对其进行编辑。感谢您的回复!我已尝试删除ComponentScan和PropertySoyrce()但是没有改变。我仍然收到相同的错误消息。你的rest控制器是什么样子的?