0
我无法让自动布线注释在我的弹簧启动应用程序中工作。自动布线导致弹簧启动应用程序出现异常
是我收到的错误是“无法自动装配领域。类型没有合格豆”
我核实,从断控制器的代码不是POJO和春天有注释。
我也无法在包外运行我的主要方法。有什么建议么?
package com.xxx.controller;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
@SpringBootApplication
public class SampleWebJspApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SampleWebJspApplication.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleWebJspApplication.class, args);
}
}
UserService类
package com.xxx.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xxx.entity.User;
import com.xxx.repository.UserRepository;
@Service
public class UserService {
@Autowired
private UserRepository userRepository;
public List<User> findAll() {
return userRepository.findAll();
}
}
UserRepository类
package com.xxx.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import com.xxx.entity.User;
public interface UserRepository extends JpaRepository<User, Integer> {
}
我删除了SpringBootApplication注释,并用ComponentScan和EnableJpaRepositories替换它。然后,我添加必要的basePackages。这并没有解决问题。还有其他建议吗? – Albert