package shop.config;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import shop.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true, proxyTargetClass = true)
@EnableJpaRepositories(basePackages="java", entityManagerFactoryRef="emf")
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserService userSevice;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/",
"/registration",
"/registrationClientInfo").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userSevice)
.passwordEncoder(NoOpPasswordEncoder.getInstance());
}
}
package shop;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
<?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>MarchenkoKohovich</groupId>
<artifactId>Shop</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
</dependency>
<!--security-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.4.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.3.Final</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
我的AppClication.Properties
spring.datasource.url=jdbc:mysql://localhost:3306/electronic?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
spring.datasource.username=root
spring.datasource.password=88fo
spring.jpa.generate-ddl=true
spring.freemarker.expose-request-attributes=true
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect
spring.jpa.hibernate.ddl-auto = create
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
同时:由:org.springframework.beans.factory.unsatisfieddependencyexception:创建名为“user service”的bean时出错:通过字段“user repo”表示的不满足的依赖关系;嵌套异常为org.springframework.beans.factory.noSuchBeanDefinitionException:没有“Shop.Repos.UserRepo”类型的合格bean可用:应至少有一个合格的自带候选bean。依赖项注释:{@org.SpringFramework.Beans.Factory.Annotation.AutoWired(required=true)}
UserService.java
package shop.service;
import shop.entity.User;
import shop.repos.UserRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
public class UserService implements UserDetailsService {
@Autowired
private UserRepo userRepo;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
return userRepo.findByUsername(username);
}
@Transactional
public Iterable<User> loadAllUsers(){
return userRepo.findAll();
}
@Transactional
public User saveUsers(User user){
return userRepo.save(user);
}
@Transactional
public void deleteUser(User user){
userRepo.delete(user);
}
@Transactional
public List<User> loadUserByActive(boolean active){
return userRepo.findByActive(active);
}
}
userrepo.java
package shop.repos;
import shop.entity.User;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
public interface UserRepo extends CrudRepository<User, Long> {
User findByUsername(String username);
List<User> findByActive(boolean active);
}
注释有问题:
@EnableJpaRepositories(basePackages="java", entityManagerFactoryRef="emf")
您尝试扫描名为“java”的包中的注释实体,但从配置文件中可以看出,实际的包是从“shop”开始的。
您应该将注释更改为:
@EnableJpaRepositories(basePackages="shop.repos", entityManagerFactoryRef="emf")
启动应用程序上下文时出错。若要显示条件报告,请在启用“调试”的情况下重新运行应用程序。2020-08-05 09:53:05.348 错误 46991 --- [ 主] o.s.boot.Spring 应用程序: 应用程序运行失败 组织.Spring框架.豆子.工厂.不满意依赖性异常:创建名称为“产品控制器”的Bean时出错:通过字段“产品存储库”表示的不满意的依赖关系;嵌套的异常是组织.spri
我尝试使用Mybatis XML配置实现一个简单的CRUD应用程序已经是第三天了,我对整个Spring生态系统还是新手。这个问题有点长,但我只分享了要点。 我有一个类: 然后我写了一个映射器 在许多教程和解答之后,我创建了一个,文件也在`Resources文件夹中。 在中,我所做的与在文件中所做的几乎相同 以下是项目结构截图: 嵌套异常是org.springframework.beans.fact
我有这个错误已经有好几个星期了,我不知道如何修复它。类似的堆栈溢出解决方案不适合我的项目。 我目前使用mysql数据库,但遇到这个问题,每当试图启动服务器: StackTrace [错误]无法执行目标组织。springframework。boot:spring boot maven插件:1.5.6。发布:在project iPbackend上运行(默认cli):运行时发生异常。null:Invoc
创建名称为clienteRestController的bean时出错:通过字段clientService表示的不满意的依赖项。 创建名称为'clientServiceImpl'的bean时出错:通过字段'client道'表示的不满意的依赖项。 创建名称为ICliente道的bean时出错:初始化方法调用失败。 嵌套异常java.lang.IllegalArgumentExcishop:不是托管类型
我查了一些类似的问题,但这些答案帮不了我。 错误 组织。springframework。豆。工厂未满足的依赖项异常:创建名为“accountController”的bean时出错:未满足的依赖项通过字段“accountService”表示;嵌套的异常是org。springframework。豆。工厂NoSuchBeanDefinitionException:没有类型为“com”的合格bean。服务
我想在我的项目中实现Spring Security性。但不管我怎么做,我总是会犯同样的错误。 我创建了必要的类(,,)。它们在同一个包下,但我得到以下错误。 这是发生问题的的一部分 2018-12-31 23:58:10.616信息9952---[main]j.LocalContainerEntityManagerFactoryBean:初始化了持久性单元“默认”的JPA EntityManage
我已经完成了我的代码,但它不工作,我不能找到任何解决方案,任何帮助将得到认可 weather.java WeatherController.java 请帮我解决这个错误