我正在尝试学习这篇spring-lemon入门教程(https://naturalprogrammer.gitbooks.io/spring-lemon-gett-started/content/index.html),但在某一点上我无法更进一步。我创建了一个新的spring starter项目(spring boot),并且能够将spring lemon添加到其中。我只做了说明,但是当我启动maven build时,测试失败了,出现了以下错误:
org.springframework.beans.factory.BeanCreationException:创建名为“LMN DemoController”的bean时出错:注入autowired依赖项失败;嵌套异常为Org.SpringFramework.Beans.Factory.BeanCreationException:无法自动连接方法:public void Com.NaturalProgrammer.Spring.Lemon.LemonController.SetLemonService(Com.NaturalProgrammer.Spring.Lemon.LemonService);嵌套异常为org.springframework.beans.factory.beanCurrentlyIncreationException:创建名为“LMN DemoService”的bean时出错:名为“LMN DemoService”的bean已作为循环引用的一部分在其原始版本中注入到其他bean[authenticationSuccessHandler]中,但最终已被包装。这意味着所述其他bean不使用bean的最终版本。这通常是过度急切的类型匹配的结果--例如,考虑使用“get BeannamesofType”并关闭“allow eagerinit”标志。
我的lmnDemoService.java
是:
package com.example;
import org.springframework.stereotype.Service;
import com.naturalprogrammer.spring.lemon.LemonService;
@Service
public class LmnDemoService extends LemonService<User, Long> {
@Override
protected User newUser() {
return new User();
}
}
它没有其他东西,只有教程说的台词。我错过了什么?
编辑:
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.naturalprogrammer.spring.lemon.LemonConfig;
@SpringBootApplication(scanBasePackageClasses = {LmndemoApplication.class, LemonConfig.class})
public class LmndemoApplication {
public static void main(String[] args) {
SpringApplication.run(LmndemoApplication.class, args);
}
}
package com.example;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.naturalprogrammer.spring.lemon.LemonController;
@RestController
@RequestMapping("/api/core")
public class LmnDemoController extends LemonController<User, Long> {
}
package com.example;
import org.springframework.stereotype.Service;
import com.naturalprogrammer.spring.lemon.LemonService;
@Service
public class LmnDemoService extends LemonService<User, Long> {
@Override
protected User newUser() {
return new User();
}
}
package com.example;
import org.springframework.context.annotation.Configuration;
import com.naturalprogrammer.spring.lemon.security.LemonSecurityConfig;
@Configuration
public class SecurityConfig extends LemonSecurityConfig {
}
ServletInitializer.java
package com.example;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(LmndemoApplication.class);
}
}
user.java
package com.example;
import javax.persistence.Entity;
import javax.persistence.Table;
import com.naturalprogrammer.spring.lemon.domain.AbstractUser;
@Entity
@Table(name="usr")
public class User extends AbstractUser<User,Long> {
private static final long serialVersionUID = 2716710947175132319L;
}
userRepository.java
package com.example;
import com.naturalprogrammer.spring.lemon.domain.AbstractUserRepository;
public interface UserRepository extends AbstractUserRepository<User, Long> {
}
#Database configuration
spring.jpa.database: MYSQL
spring.jpa.hibernate.ddl-auto: update
spring.datasource.url: jdbc:mysql://localhost:3306/mydatabase
spring.datasource.username: myuser
spring.datasource.password: mypassword
#DevTools configuration
spring.devtools.livereload.enabled: false
spring.devtools.restart.enabled: false
#Application URL
#lemon.application-url: http://localhost:9000
#reCAPTCHA configuration
#lemon.recaptcha.sitekey: your google recaptcha site key
#lemon.recaptcha.secretkey: your google recaptcha secret key
#Remember me configuration
#lemon.remember-me-key: someSecret
#First administrator
lemon.admin.username: admin@example.com
lemon.admin.password: admin
#Email configuration
#spring.mail.host = smtp.gmail.com
#spring.mail.username = xxxxxx@gmail.com
#spring.mail.password = xxxxxx
#
#spring.mail.properties.mail.smtp.auth = true
#spring.mail.properties.mail.smtp.socketFactory.port = 465
#spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory
#spring.mail.properties.mail.smtp.socketFactory.fallback = false
#spring.mail.properties.mail.smtp.ssl.enable = true
#Handling cross origin requests configuration
#lemon.cors.allowed-origins: http://localhost:9000
#This will disable the protection against JSON vulnerability
#lemon.enabled.json-prefix: false
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>lmndemo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</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-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Spring-lemon -->
<dependency>
<groupId>com.naturalprogrammer.spring</groupId>
<artifactId>spring-lemon</artifactId>
<version>0.8.5</version><!-- See https://github.com/naturalprogrammer/spring-lemon/releases for latest release -->
</dependency>
</dependencies>
<build>
<finalName>lmndemo</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
在我看来像是一个循环参考问题。在我的环境中没有发生这种情况,我认为理想情况下Spring应该能够自己解决它,但我认为最好的方法是修复Spring Lemon代码,使其更加健壮。
那么,您是否可以尝试在工作区中签出的Spring Lemon代码中的AuthenticationSuccessHandler
类的SetleMonService
方法上添加一个@lazy
注释?使其外观如下:
@Autowired
@Lazy // add this line
public void setLemonService(LemonService<?, ?> lemonService) {
this.lemonService = lemonService;
}
我以前没有尝试过@lazy
,但我认为它应该可以工作。如果不是,我们需要考虑另一种方法来打破循环依赖关系。
让我知道。找到解决方案后,我将检查Spring Lemon存储库的修复程序。
我试图编译一个非常简单的程序,将包含3个用户的简单表保存到http://localhost/phpmyadmin,以清空名为,users ' '的数据库,但它仍然显示异常,您可以看到。 1个异常org.springframework.beans.factory。BeanCreationException:创建在类路径资源[org/springframework/boot/autoconfigure
当我启动Weblogic时(使用jar:hibernate-core-4.3.6.final.jar和hibernate-jpa-2.1-api-1.0.0.final.jar),遇到以下错误信息: 无法自动连接字段:private org.hibernate.sessionFactory com.nscorp.lars.shopleveling.core.dao.impl.Dataloaddao
我在SpringBoot应用程序中创建HighHendRestClient bean时遇到一个错误。我已经做了一个测试'app',在那里我检查了我可以实例化我想要的对象,然后进行我想要的调用,我现在正在做一个新的应用程序的婴儿步骤。 就我所能看到的(我还没有用它做太多...) 当我添加它时(最初我传入了RestClient bean,但现在我临时创建了一个本地对象,以便更清晰) 我得到这个java
我使用的是Spring 3.1.4 服务实现 DAO实现 web.xml
严重:上下文初始化失败org.springframework.beans.factory.BeanCreationException:创建ServletContext资源[/web-inf/mvc-dispatcher-servlet.xml]中定义的名为“org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerM
我是春靴新来的。我试图用hibernate连接MySql db,但当我命令 mvn Spring-Boot:Run 我的pom.xml在这里: hibernate.dialog:org.hibernate.dialt.mysql5dialog hibernate.show_sql:true hibernate.hbm2ddl.auto:update entitymanager.packageSto