小编Pav*_*ndu的帖子

考虑在配置中定义类型的Bean

我正在关注本教程(https://www.youtube.com/watch?v=Hu-cyytqfp8),并尝试在Spring Boot中连接到远程服务器上的MongoDB。运行应用程序时,我收到以下消息。

说明:com.mongotest.demo.Seeder中构造函数的参数0需要找不到“ com.mongotest.repositories.StudentRepository”类型的Bean。

行动:考虑在配置中定义一个类型为“ com.mongotest.repositories.StudentRepository”的bean。

项目结构。

在此处输入图片说明

这是我的课

    @Document(collection = "Students")
    public class Student {

        @Id
        private String number;
        private String name;
        @Indexed(direction = IndexDirection.ASCENDING)
        private int classNo;

    //Constructor and getters and setters.
    }

    ================================

    @Repository
    public interface StudentRepository extends MongoRepository<Student, String>{

    }

    ================================

    @Component
    @ComponentScan({"com.mongotest.repositories"})
    public class Seeder implements CommandLineRunner{

        private StudentRepository studentRepo;

        public Seeder(StudentRepository studentRepo) {
            super();
            this.studentRepo = studentRepo;
        }

        @Override
        public void run(String... args) throws Exception {
            // TODO Auto-generated method stub

            Student s1 …
Run Code Online (Sandbox Code Playgroud)

java spring mongodb spring-boot

5
推荐指数
1
解决办法
2万
查看次数

org.thymeleaf.templatemode.StandardTemplateModeHandlers 无法解析

在我的 Spring boot API 中,我需要使用 Thymeleaf 发送电子邮件。因此,我选择了这个教程。但是,在添加ThymeleafConfig.java 时,STS 抛出以下错误。

导入 org.thymeleaf.templatemode.StandardTemplateModeHandlers 无法解析

this answer中所述,我按如下方式更改了依赖项。但它没有解决问题。

<dependency>
  <groupId>org.thymeleaf</groupId>
  <artifactId>thymeleaf</artifactId>
  <version>3.0.11.RELEASE</version>
</dependency>

<dependency>
  <groupId>nz.net.ultraq.thymeleaf</groupId>
  <artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

百里香叶配置文件

import java.nio.charset.StandardCharsets;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
//following import is not resolved
import org.thymeleaf.templatemode.StandardTemplateModeHandlers;
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver;


@Configuration
public class ThymeleafConfig {

  @Bean
  public ClassLoaderTemplateResolver htmlTemplateResolver(){
    ClassLoaderTemplateResolver emailTemplateResolver = new ClassLoaderTemplateResolver();
    emailTemplateResolver.setPrefix("/templates/");
    emailTemplateResolver.setSuffix(".html");
      emailTemplateResolver.setTemplateMode(StandardTemplateModeHandlers.HTML5.getTemplateModeName());
    emailTemplateResolver.setCharacterEncoding(StandardCharsets.UTF_8.name());
    return emailTemplateResolver;
 }
}
Run Code Online (Sandbox Code Playgroud)

java thymeleaf spring-boot

5
推荐指数
1
解决办法
1864
查看次数

React js:在单页面应用程序中渲染多个索引html

我正在使用 React 和 Node.js 开发一个电子商务网站。我面临下面描述的两个问题。

  1. 我有两个不同的主.html文件用于管理端和前端端。因此,我使用内置的 React 管理模板,其中index.html在项目启动时加载。我的问题是如何加载另一个.html前端设计大师?

  2. 我想使用 Node.js 作为后端。因此,我无法将 node.js 与 React 前端或管理端集成,如果 React 应用程序运行,它们将运行。

任何建议或解决步骤将受到高度赞赏。

nodes e-commerce node.js reactjs

5
推荐指数
1
解决办法
3575
查看次数

使用 Facebook 登录时不会触发 onLoginFinished 回调

我建立一个简单的阵营原生应用程序,它实现“登录与Facebook的”使用反应本地-fbsdk 我可以登录和注销从按钮改变登录注销时记录有凭据,但onLoginFinished回调永远不会被解雇,虽然onLogoutFinished工作正常。

这是我的代码:

import React, { Component } from 'react';
import { View,Alert,Button,Text } from 'react-native';
import { LoginButton, AccessToken } from 'react-native-fbsdk';

export default class Login extends Component {
  constructor(props) {
    super(props);
    this.state = {
      userInfo: null
    }
  }

  onFacebookLoginFinished = (error, result) => {
    if (error) {
      Alert.alert("login has error: " + result.error);
    } else if (result.isCancelled) {
      Alert.alert("login is cancelled.");
    } else {
      AccessToken.getCurrentAccessToken().then(
        (data) => {
          Alert.alert(data.accessToken.toString()) …
Run Code Online (Sandbox Code Playgroud)

react-native react-native-fbsdk

5
推荐指数
1
解决办法
643
查看次数

在构建时React Native抛出访问被拒绝错误

我在控制台中遇到此错误。

失败:构建失败,发生异常。

出了什么问题:在最新检查期间,无法捕获任务':react-native-linear-gradient:processDebugManifest'属性'aaptFriendlyManifestOutputDirectory'的输出文件快照。

> java.nio.file.AccessDeniedException:P:\ React Native \ JDream \ node_modules \ react-native-linear-gradient \ android \ build \ intermediates \ manifests \ aapt \ debug

android react-native

4
推荐指数
1
解决办法
1575
查看次数

如何使用 React 制作垂直标签

有人可以为我提供一种使用 React 创建垂直选项卡的方法吗?

我尝试了各种 npm 包,如 react-web-tabs、reactstrap 和 react-bootstrap。最后两个只有水平选项卡的示例。React-web-tabs 在他们的文档中有一个垂直选项卡示例,但它不起作用。

import { Tabs, Tab, TabPanel, TabList } from 'react-web-tabs';

class NewNavigation extends React.Component{
render(){
return(
    <Tabs defaultTab="vertical-tab-one" vertical>
        <TabList>
            <Tab tabFor="vertical-tab-one">Tab 1</Tab>
            <Tab tabFor="vertical-tab-two">Tab 2</Tab>
            <Tab tabFor="vertical-tab-three">Tab 3</Tab>
        </TabList>

        <TabPanel tabId="vertical-tab-one">
            <p>Tab 1 content</p>
        </TabPanel>

        <TabPanel tabId="vertical-tab-two">
            <p>Tab content</p>
        </TabPanel>

        <TabPanel tabId="vertical-tab-three">
            <p>Tab 3 content</p>
        </TabPanel>
    </Tabs>
    );
}
}
Run Code Online (Sandbox Code Playgroud)

到目前为止,它显示基本的水平选项卡,我想修复此代码,因为它显示垂直选项卡。如果您推荐任何其他方式,也非常感谢。

vertical-alignment reactjs

4
推荐指数
1
解决办法
6928
查看次数

在 Go 中将 SQL 行转换为 JSON 格式

在我正在开发的 REST API 中,有一个/courses端点以 JSON 格式返回从 SQL 表查询的一些数据。但是,我找不到将查询数据(行)转换为 JSON 的方法。

func GetCoursesEndpoint(w http.ResponseWriter, req *http.Request) {
  db, err := sql.Open("mysql", "root:@/academy")
  checkErr(err)

  rows, err := db.Query("SELECT course_name,price FROM course;")
  checkErr(err)

  //how to convert returned rows to JSON?
  msg, err := json.Marshal(rows)
  checkErr(err)

  json.NewEncoder(w).Encode(msg)
  return  
}
Run Code Online (Sandbox Code Playgroud)

mysql rest go

4
推荐指数
1
解决办法
1965
查看次数

有条件地在 React 中输入所需的输入

在我的 React 应用程序中的表单中,如果类别设置为滚动,我想制作一组必需的输入(长度和规格) 。我该怎么做?提前致谢。

 <Form.Group as={Col}>
   <label>Category</label>
   <Form.Control
     as="select"
     name="category"
     defaultValue={this.state.category}
     onChange={this.catControl}
   >
    <option>printed</option>
    <option>roll</option>
  </Form.Control>
</Form.Group>

<Form.Row>
 <Form.Group as={Col}>
   <label>Length(cm)</label>
   //required if category is set to "roll". How can I do that?
   <Form.Control name="length" defaultValue={this.state.length} />
 </Form.Group>

 <Form.Group as={Col}>
   <label>Gauge(mm)</label>
   <Form.Control name="gauge" defaultValue={this.state.gauge} />
 </Form.Group>
</Form.Row>
Run Code Online (Sandbox Code Playgroud)

forms required reactjs

3
推荐指数
1
解决办法
4807
查看次数

如何比较密码文本和bcrypt哈希?

我的应用程序中有一个用例,该用例应防止用户在重置密码时选择其后三个密码之一。我在前端使用Angular,在后端使用Spring Boot。在我的情况下,用户密码存储为bcrypt哈希。

如何将用户输入的密码与最近存储的3个bcrypt密码进行比较?

当我运行以下代码片段示例时,

BCryptPasswordEncoder b = new BCryptPasswordEncoder();

    for(int i =0;i<10;i++) {
        System.out.println(b.encode("passw0rd"));

    }
Run Code Online (Sandbox Code Playgroud)

它生成以下bcrypt哈希。每个哈希都是不同的,这是合理的,因为当我检查时org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder,可以看到生成的盐是随机值。

$2a$10$tztZsPFZ.T.82Gl/VIuMt.RDjayTwuMLAkRkO9SB.rd92vHWKZmRm
$2a$10$yTHyWDmcCBq3OSPOxjj4TuW9qXYE31CU.fFlWxppii9AizL0lKMzO
$2a$10$Z6aVwg.FNq/2I4zmDjDOceT9ha0Ur/UKsCfdADLvNHiZpR7Sz53fC
$2a$10$yKDVeOUvfTQuTnCHGJp.LeURFcXK6JcHB6lrSgoX1pRjxXDoc8up.
$2a$10$ZuAL06GS7shHz.U/ywb2iuhv2Spubl7Xo4NZ7QOYw3cHWK7/7ZKcC
$2a$10$4T37YehBTmPWuN9j.ga2XeF9GHy6EWDhQS5Uc9bHvJTK8.xIm1coS
$2a$10$o/zxjGkArT7YdDkrk5Qer.oJbZAYpJW39iWAWFqbOhpTf3FmyfWRC
$2a$10$eo7yuuE2f7XqJL8Wjyz.F.xj78ltWuMS1P0O/I6X7iNPwdsWMVzu6
$2a$10$3ErH2GtZpYJGg1BhfgcO/uOt/L2wYg4RoO8.fNRam458WWdymdQLW
$2a$10$IksOJvL/a0ebl4R2/nbMQ.XmjNARIzNo8.aLXiTFs1Pxd06SsnOWa
Run Code Online (Sandbox Code Playgroud)

Spring安全配置。

  @Configuration
    @Import(SecurityProblemSupport.class)
    @EnableWebSecurity
    @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
    public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

        @PostConstruct
        public void init() {
            try {
                authenticationManagerBuilder
                    .userDetailsService(userDetailsService)
                    .passwordEncoder(passwordEncoder());
            } catch (Exception e) {
                throw new BeanInitializationException("Security configuration failed", e);
            }
        }
       @Bean
        public PasswordEncoder passwordEncoder() {
            return new BCryptPasswordEncoder();
        }
    }
Run Code Online (Sandbox Code Playgroud)

spring cryptography spring-security bcrypt spring-boot

2
推荐指数
1
解决办法
566
查看次数

反应本机突然无法解决模块“ fs”错误

我突然收到模块“ fs”无法解决的错误。但是我没有使用此模块,也没有更改任何内容。我的应用程序启动时突然返回此错误。

错误:捆绑失败:错误:无法解析模块fs/Path/to/Project/node_modules/handlebars/lib/index.js:模块fs 不会在急速模块地图存在

这可能与https://github.com/facebook/react-native/issues/4968有关要解决此 问题,请尝试以下操作:

  1. 清除看门人手表:watchman watch-del-all
  2. 删除node_modules文件夹:rm -rf node_modules && npm install
  3. 重置Metro Bundler缓存:rm -rf /tmp/metro-bundler-cache-*npm start -- --reset-cache
  4. 删除急速缓存:rm -rf /tmp/haste-map-react-native-packager-*

我已经尝试了四个步骤来解决,但没有任何帮助。任何想法可能有什么问题吗?

fs reactjs react-native react-navigation

2
推荐指数
2
解决办法
898
查看次数