- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我的应用程序运行,但控制台中没有显示任何有关映射的信息。我的应用程序类文件位于 Controller 上方,并且还添加了 @ComponentScan(basePackages : "com.org.name.controller") 来扫描 Controller 。控制台中仍然没有显示映射。我在 Controller 类中注释掉了 @Autowired,因为我收到以下错误:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-07-12 11:05:16.014 ERROR 14104 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field userService in com.homzhub.lms.controller.UserController required a bean of type 'com.homzhub.lms.service.UserService' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.homzhub.lms.service.UserService' in your configuration.
主类:
package com.homzhub.lms;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan(basePackages = {"com.homzhub.lms.controller"})
//@EnableJpaRepositories("repository")
//@EnableAutoConfiguration
public class LmsApplication{
public static void main(String[] args){
SpringApplication.run(LmsApplication.class, args);
}
}
预约 Controller :
package com.homzhub.lms.controller;
import java.security.Principal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.homzhub.lms.entity.Appointment;
import com.homzhub.lms.entity.User;
import com.homzhub.lms.service.AppointmentService;
import com.homzhub.lms.service.UserService;
@Controller
@RequestMapping(path = "/appointment")
public class AppointmentController {
// @Autowired
private AppointmentService appointmentService;
//@Autowired
private UserService userService;
@RequestMapping(value = "/create", method = RequestMethod.GET)
public void createAppointment(Model model) {
Appointment appointment = new Appointment();
model.addAttribute("appointment", appointment);
model.addAttribute("dateString", "");
}
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String createAppointmentPost(@ModelAttribute("appointment") Appointment appointment, @ModelAttribute("dateString") String date, Model model, Principal principal) throws ParseException {
SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd hh:mm");
Date d1 = format1.parse(date);
appointment.setDate(d1);
User user = userService.findByUsername(principal.getName());
appointment.setUser(user);
appointmentService.createAppointment(appointment);
return "redirect:/userFront";
}
}
pom.xml 文件:
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<!-- <version>1.5.21.RELEASE</version> -->
<version>2.1.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.homzhub</groupId>
<artifactId>lms</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>lms</name>
<description>Lead Management System</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<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-starter-jdbc</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>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
控制台输出。在 Controller 类中注释掉 @Autowired 后,应用程序运行但未完成映射:
2019-07-12 12:58:04.638 INFO 18828 --- [ main] com.homzhub.lms.LmsApplication : Starting LmsApplication v0.0.1-SNAPSHOT on rms-Lenovo-ideapad-330-15IKB with PID 18828 (/home/rms/lms/target/lms-0.0.1-SNAPSHOT.jar started by rms in /home/rms/lms)
2019-07-12 12:58:04.644 INFO 18828 --- [ main] com.homzhub.lms.LmsApplication : No active profile set, falling back to default profiles: default
2019-07-12 12:58:05.941 INFO 18828 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-07-12 12:58:06.161 INFO 18828 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 204ms. Found 13 repository interfaces.
2019-07-12 12:58:06.849 INFO 18828 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$d931452d] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-07-12 12:58:07.301 INFO 18828 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-07-12 12:58:07.350 INFO 18828 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-07-12 12:58:07.350 INFO 18828 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.21]
2019-07-12 12:58:07.484 INFO 18828 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-07-12 12:58:07.484 INFO 18828 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2751 ms
2019-07-12 12:58:07.952 INFO 18828 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-07-12 12:58:08.286 INFO 18828 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2019-07-12 12:58:08.388 INFO 18828 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-07-12 12:58:08.519 INFO 18828 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.3.10.Final}
2019-07-12 12:58:08.521 INFO 18828 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2019-07-12 12:58:08.773 INFO 18828 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2019-07-12 12:58:09.175 INFO 18828 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2019-07-12 12:58:10.967 INFO 18828 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-07-12 12:58:12.284 INFO 18828 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-07-12 12:58:12.364 WARN 18828 --- [ main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2019-07-12 12:58:12.923 INFO 18828 --- [ main] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page template: index
2019-07-12 12:58:13.211 INFO 18828 --- [ main] .s.s.UserDetailsServiceAutoConfiguration :
Using generated security password: f1e93a8f-d01a-4050-8724-87ff348fab02
2019-07-12 12:58:13.388 INFO 18828 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@1dcca8d3, org.springframework.security.web.context.SecurityContextPersistenceFilter@6daf2337, org.springframework.security.web.header.HeaderWriterFilter@70e3f36f, org.springframework.security.web.csrf.CsrfFilter@3c7cfcbb, org.springframework.security.web.authentication.logout.LogoutFilter@7d755813, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@4e25147a, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter@60e5272, org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter@5631962, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@56303475, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@250b236d, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@432034a, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@52a70627, org.springframework.security.web.session.SessionManagementFilter@23e44287, org.springframework.security.web.access.ExceptionTranslationFilter@1bfe3203, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@71870da7]
2019-07-12 12:58:13.517 INFO 18828 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-07-12 12:58:13.520 INFO 18828 --- [ main] com.homzhub.lms.LmsApplication : Started LmsApplication in 9.518 seconds (JVM running for 10.158)
用户服务类:
package com.homzhub.lms.service;
import java.util.List;
import java.util.Set;
import org.springframework.stereotype.Service;
import com.homzhub.lms.entity.User;
import com.homzhub.lms.security.UserRole;
//@Service("userDetailsService")
@Service
public interface UserService{
User findByUsername(String username);
User findByEmail(String email);
// User findByPhoneNumber(String phoneNumber);
boolean checkUserExists(String username, String email);
boolean checkUsernameExists(String username);
boolean checkEmailExists(String email);
void save(User user);
User createUser(User user, Set<UserRole> userRoles);
User saveUser(User user);
List<User> findUserList();
void enableUser(String username);
void disableUser(String username);
}
最佳答案
如果还没有,您需要将 UserService
定义为组件,或者更恰本地说定义为服务。如果它已经是你必须映射它,考虑到 Spring 应该自己做这件事,这有点奇怪。
关于java - 休息 Controller 未在 Spring Boot 中映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57002302/
我需要将文本放在 中在一个 Div 中,在另一个 Div 中,在另一个 Div 中。所以这是它的样子: #document Change PIN
奇怪的事情发生了。 我有一个基本的 html 代码。 html,头部, body 。(因为我收到了一些反对票,这里是完整的代码) 这是我的CSS: html { backgroun
我正在尝试将 Assets 中的一组图像加载到 UICollectionview 中存在的 ImageView 中,但每当我运行应用程序时它都会显示错误。而且也没有显示图像。 我在ViewDidLoa
我需要根据带参数的 perl 脚本的输出更改一些环境变量。在 tcsh 中,我可以使用别名命令来评估 perl 脚本的输出。 tcsh: alias setsdk 'eval `/localhome/
我使用 Windows 身份验证创建了一个新的 Blazor(服务器端)应用程序,并使用 IIS Express 运行它。它将显示一条消息“Hello Domain\User!”来自右上方的以下 Ra
这是我的方法 void login(Event event);我想知道 Kotlin 中应该如何 最佳答案 在 Kotlin 中通配符运算符是 * 。它指示编译器它是未知的,但一旦知道,就不会有其他类
看下面的代码 for story in book if story.title.length < 140 - var story
我正在尝试用 C 语言学习字符串处理。我写了一个程序,它存储了一些音乐轨道,并帮助用户检查他/她想到的歌曲是否存在于存储的轨道中。这是通过要求用户输入一串字符来完成的。然后程序使用 strstr()
我正在学习 sscanf 并遇到如下格式字符串: sscanf("%[^:]:%[^*=]%*[*=]%n",a,b,&c); 我理解 %[^:] 部分意味着扫描直到遇到 ':' 并将其分配给 a。:
def char_check(x,y): if (str(x) in y or x.find(y) > -1) or (str(y) in x or y.find(x) > -1):
我有一种情况,我想将文本文件中的现有行包含到一个新 block 中。 line 1 line 2 line in block line 3 line 4 应该变成 line 1 line 2 line
我有一个新项目,我正在尝试设置 Django 调试工具栏。首先,我尝试了快速设置,它只涉及将 'debug_toolbar' 添加到我的已安装应用程序列表中。有了这个,当我转到我的根 URL 时,调试
在 Matlab 中,如果我有一个函数 f,例如签名是 f(a,b,c),我可以创建一个只有一个变量 b 的函数,它将使用固定的 a=a1 和 c=c1 调用 f: g = @(b) f(a1, b,
我不明白为什么 ForEach 中的元素之间有多余的垂直间距在 VStack 里面在 ScrollView 里面使用 GeometryReader 时渲染自定义水平分隔线。 Scrol
我想知道,是否有关于何时使用 session 和 cookie 的指南或最佳实践? 什么应该和什么不应该存储在其中?谢谢! 最佳答案 这些文档很好地了解了 session cookie 的安全问题以及
我在 scipy/numpy 中有一个 Nx3 矩阵,我想用它制作一个 3 维条形图,其中 X 轴和 Y 轴由矩阵的第一列和第二列的值、高度确定每个条形的 是矩阵中的第三列,条形的数量由 N 确定。
假设我用两种不同的方式初始化信号量 sem_init(&randomsem,0,1) sem_init(&randomsem,0,0) 现在, sem_wait(&randomsem) 在这两种情况下
我怀疑该值如何存储在“WORD”中,因为 PStr 包含实际输出。? 既然Pstr中存储的是小写到大写的字母,那么在printf中如何将其给出为“WORD”。有人可以吗?解释一下? #include
我有一个 3x3 数组: var my_array = [[0,1,2], [3,4,5], [6,7,8]]; 并想获得它的第一个 2
我意识到您可以使用如下方式轻松检查焦点: var hasFocus = true; $(window).blur(function(){ hasFocus = false; }); $(win
我是一名优秀的程序员,十分优秀!