小编raw*_*215的帖子

角度误差:当在子模块中声明时,'组件'X'不包含在模块中......

我正在尝试将我的对话框合并到一个Angular模块中,但是我在IDE中遇到了一个linting错误:

组件"X"未包含在模块中,并且在模板内不可用.考虑将其添加到NgModule声明中.

尽管存在此错误,应用程序仍会加载并成功运行.

示例组件定义

import { Component, Inject, OnInit, ViewEncapsulation } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';

export interface AlertDialogData {
  titleText: string;
  dismissalText: string;
  contentComponent: string;
}

@Component({
  selector: 'app-alert-dialog',
  templateUrl: './alert-dialog.component.html',
  styleUrls: ['./alert-dialog.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class AlertDialogComponent implements OnInit {

  constructor(private dialogRef: MatDialogRef<AlertDialogComponent>, @Inject(MAT_DIALOG_DATA) public data: any) { }

  ngOnInit() {
  }

  handleCloseClick(): void {
    this.dialogRef.close();
  }

}
Run Code Online (Sandbox Code Playgroud)

子模块制作声明/导出

import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import …
Run Code Online (Sandbox Code Playgroud)

lint typescript angular-cli angular

17
推荐指数
3
解决办法
2万
查看次数

如何使用DaoAuthenticationProvider以编程方式使用Spring Security对用户进行身份验证

我想知道我在这里做错了什么来验证用户.我有一个应用程序,用户通过几个步骤来激活他们的帐户,这样做我想绕过登录表单并将它们直接带到他们的仪表板.

这是我的自动登录功能:

protected void automatedLogin(String username, String password, HttpServletRequest request) {

        try {
            // Must be called from request filtered by Spring Security, otherwise SecurityContextHolder is not updated
            CustomUserDetailsService udService = new CustomUserDetailsService(userDAO, request);
            UserDetails uDetails = udService.loadUserByUsername(username);
            UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(uDetails, password);
            token.setDetails(new WebAuthenticationDetails(request));
            DaoAuthenticationProvider authenticator = new DaoAuthenticationProvider();
            Authentication authentication = authenticator.authenticate(token);
            SecurityContextHolder.getContext().setAuthentication(authentication);
        } catch (Exception e) {
            e.printStackTrace();
            SecurityContextHolder.getContext().setAuthentication(null);
        }

    }
Run Code Online (Sandbox Code Playgroud)

我必须使用DaoAuthenticationProvider类作为我的身份验证提供程序.我已经验证我正在获取包含正确凭据,ID,权限角色等的UserDetails模型.

当它调用authenticate方法时,我会在DaoAuthenticationProvider类中的某个地方遇到Null Pointer:

org.springframework.security.authentication.dao.DaoAuthenticationProvider.retrieveUser(DaoAuthenticationProvider.java:109)org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.authenticate上的org.springframework.security.authentication.AuthenticationServiceException(AbstractUserDetailsAuthenticationProvider.java:132 )在com.bosch.actions.BaseController.doAutoLogin(BaseController.java:659)...引起:org.springframework.security.authentication.dao.DaoAuthenticationProvider.retrieveUser(DaoAuthenticationProvider.java:101)中的java.lang.NullPointerException

我真的不确定什么是null,因为我没有可用的源代码.

编辑 我能够在这里找到源代码 - https://github.com/SpringSource/spring-security/blob/master/core/src/main/java/org/springframework/security/authentication/dao/DaoAuthenticationProvider.java

通过在对象上显式设置UserDetailsS​​ervice,我能够绕过Null指针:

authenticator.setUserDetailsService(udService);
Run Code Online (Sandbox Code Playgroud)

但是,当我知道提供的密码是正确的时,我得到了错误的凭证异常,因为我已经在代码中早先的UserDetails对象中的调试器中看到了它.

org.springframework.security.authentication.BadCredentialsException:org.springframework.security.authentication.dao.DaoAuthenticationProvider.additionalAuthenticationChecks(DaoAuthenticationProvider.java:87)中的错误凭据,位于org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.authenticate(AbstractUserDetailsAuthenticationProvider. Java的:149)

java authentication spring dao spring-security

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

Angular Material:如何将floatPlaceholder设置为never

图书馆:角度材料(材料2)

我想使用MdInputContainer的floatPlaceholder指令,以便占位符/提示永远不会浮动.

我没有看到它在文档中指出它所期望的值的位置:

@Input()floatPlaceholder:占位符是否应始终浮动,永远不会浮动或浮动,因为用户键入.

取自:https://material.angular.io/components/input/api

<md-input-container [floatPlaceholder]="false"> <input type="text" mdInput placeholder="Search..." </md-input-container>

我试过false"never"该值作为我最好的猜测,但也阻止了占位符从浮在上面输入.

html angular-material2 angular

6
推荐指数
1
解决办法
5889
查看次数

名称为“defaultReference”的反序列化和多个反向引用属性

我正在尝试使用 Jackson 1.9 将嵌套 JSON 对象反序列化为 POJO,但遇到了麻烦。下面是类以及我尝试解析的示例 JSON 字符串。

(省略 getter 和 setter)

JSON 字符串:

sellerJson = "[{\"id\":\"1\",\"first_name\":\"Joe\",\"last_name\":\"Sellerman\",\"company\":\"NY CANYON RANCH\"," +
                    "\"prorated_sellers\":[{\"first_name\":\"Steve\",\"last_name\":\"Jobs\",\"company\":\"NY CANYON RANCH\"}," +
                    "{\"first_name\":\"Lorne\",\"last_name\":\"Michaels\",\"company\":\"NY CANYON RANCH\"}]," +
                    "\"pens\":[{\"id\":\"2\",\"pen_no\":\"902\"}]}]";
Run Code Online (Sandbox Code Playgroud)

Java类:

@Table(name="seller")
public class SellerModel implements Serializable, Comparable<SellerModel> {

    private static final long serialVersionUID = 201302111531L;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="id")  
    private Integer id;

    @Column()
    private String first_name;

    @Column()
    private String last_name;

    @Column()
    private String company;

    @Column()
    private Boolean is_prorated;

    @JsonIgnore
    @ManyToOne()
    @JoinColumn(name="parent_seller_id", referencedColumnName="id")
    private SellerModel parent_seller;

    @JsonManagedReference(value="seller-prorated")
    @OneToMany(mappedBy = "parent_seller", cascade={CascadeType.ALL}, …
Run Code Online (Sandbox Code Playgroud)

java json jackson

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

JAXB Unmarshaller - 意外元素异常

我正在使用 JAXB 解析器将通过 http 请求发送的 XML 转换为 Java 对象,同时根据我的 XSD 模式对其进行验证。问题在于,当调用 unmarshal() 方法时,它会引发此异常:

javax.xml.bind.UnmarshalException:意外元素(uri:“ http://www.somedomain.com/ ”,本地:“assign”)。预期元素为(无)

如果我从我的根 XML 元素中删除命名空间,它会引发相同的异常,其中 uri 部分为空:

javax.xml.bind.UnmarshalException: 意外元素 (uri:"", local:"assign")。预期元素为(无)

解组代码:

            ServletInputStream xmlFile = request.getInputStream();

            SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            Schema schema = sf.newSchema(new File("PatientAssignment.xsd"));

            JAXBContext jc = JAXBContext.newInstance(AssignType.class);

            Unmarshaller unmarshaller = jc.createUnmarshaller();
            unmarshaller.setSchema(schema);
            unmarshaller.setEventHandler(new AssignValidationEventHandler(patientResponses));
            assignments = (AssignType) unmarshaller.unmarshal(xmlFile);
Run Code Online (Sandbox Code Playgroud)

我的 Java 类和 package-info.java:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "AssignType", namespace = "http://www.somedomain.com/", propOrder = {
    "patient"
})
public class AssignType {
    @XmlElement(namespace = "http://www.somedomain.com/", required = true) …
Run Code Online (Sandbox Code Playgroud)

java xml parsing jaxb unmarshalling

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

Run As JUnit没有出现在Eclipse中 - 使用JUnit4

我正在尝试为我的网络应用程序编写JUnit4测试,他们以前一直工作正常.但是,现在当我尝试通过右键单击类文件来运行测试 - >运行方式 - > JUnit测试我没有看到该选项.我想这可能是因为一位同事在事故中提交了一些Eclipse设置/属性文件.我在运行10.6.X的Mac上使用Eclipse Helios.

我注意到测试类中的图标从"填充"J变为"泡沫"J,我不确定这是否表示某种问题:

在此输入图像描述

我已经仔细检查并确保JUnit4在我的构建路径上,并且我已经转到Eclipse - > Preferences - > JUnit窗格并验证是否正在使用JUnit4导入.

我的测试类看起来像这样:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( { "classpath*:/resources/action-test-appconfig.xml" })
@Transactional
public class UserControllerTest extends BaseStrutsTestCase<UserController> {

    /**
     * Tests the ability of a user to change their login username
     * @throws Exception
     */
    @Test
    public void testChangeLogin() throws Exception {
Run Code Online (Sandbox Code Playgroud)

任何想法和建议表示赞赏.

java eclipse junit unit-testing junit4

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

AmazonS3Client无法连接

我正在尝试连接到我的AWS S3存储桶,以按照这些链接的说明上传文件.


http://docs.aws.amazon.com/AmazonS3/latest/dev/UploadObjSingleOpJava.html http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/credentials.html#credentials-specify-provider


出于某种原因,当它试图实例化AmazonS3Client对象时,它会抛出一个被吞下的异常并退出我的Struts Action.因此,我没有太多信息可以调试.

我已经尝试了默认凭据配置文件(〜/ .aws/credentials)方法和显式秘密和访问密钥(新的BasicAWSCredentials(access_key_id,secret_access_key)

/**
 * Uses the secret key and access key to return an object for accessing AWS features
 * @return BasicAWSCredentials
 */
public static BasicAWSCredentials getAWSCredentials() {
    final Properties props = new Properties();
    try {
        props.load(Utils.class.getResourceAsStream("/somePropFile"));
        BasicAWSCredentials credObj = new BasicAWSCredentials(props.getProperty("accessKey"), 
                props.getProperty("secretKey"));
        return credObj;
    }  catch (IOException e) {
        log.error("getAWSCredentials IOException" + e.getMessage());
        return null;
    }
    catch (Exception e) {
        log.error("getAWSCredentials Exception: " + e.getMessage());
        e.printStackTrace();
        return null;
    } …
Run Code Online (Sandbox Code Playgroud)

java amazon-s3 amazon-web-services

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

JAXB验证错误-cvc-complex-type.2.4.a:发现无效的内容(从元素'codeSystem'开始)。预期为“ {codeSystem}”之一

我正在尝试解析和验证XML(jaxb-impl-2.2.4.jar),但出现错误:

cvc-complex-type.2.4.a:发现无效的内容(从元素“ codeSystem”开始)。预期为“ {codeSystem}”之一。

我不确定是什么原因造成的,因为我认为我的XML看起来正确。

codeSystem的架构要求:

<xs:complexType name="GenericPropertyType">
     <xs:element name="codeSystem" type="tns:CodeSystem">
     </xs:element>
     <xs:element name="code" type="tns:Code">
     </xs:element>
     <xs:element name="codeText" type="tns:CodeText" minOccurs="0">
     </xs:element>
</xs:complexType>
Run Code Online (Sandbox Code Playgroud)

codeSystem所属的GenericProperty Java类:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "GenericPropertyType", propOrder = {
    "codeSystem",
    "code",
    "codeText"
})
public class GenericPropertyType {

    @XmlElement(required = true)
    protected String codeSystem;
    @XmlElement(required = true)
    protected String code;
    @XmlElement
    protected String codeText;

    /**
     * Getters and Setters ommitted.
     * 
     */
}
Run Code Online (Sandbox Code Playgroud)

解析的XML:

<genericProperty>
    <codeSystem>8B-30-33</codeSystem>
    <code>EMAIL_RETRY_COUNT</code>
    <codeText>5</codeText>
</genericProperty>
Run Code Online (Sandbox Code Playgroud)

我已经尝试过在genericPropertycodeSystem元素中不提供名称空间的情况,xmlns="http://www.somedomain.com/context"但是错误仍然相同。有任何想法吗?

编辑 模式中的CodeSystem类型:

<xs:simpleType …
Run Code Online (Sandbox Code Playgroud)

java xml validation parsing jaxb

0
推荐指数
1
解决办法
5062
查看次数

Java SimpleDateFormat在Date对象中返回错误的值

我正在尝试解析一个字符串以获取Date对象,但它总是返回Sun. 2012年12月30日为日期.有没有人对我做错了什么有任何想法?

我使用YYYY-MM-dd格式的字符串使用相同的代码,它工作得很好,所以我不确定为什么切换到这种格式会导致问题.

 public static Date getDateObjFromStr(String dateStr)
{
    DateFormat formatter = new SimpleDateFormat("MM/dd/YYYY");
    Date dateObj;
    try {
        dateObj = formatter.parse(dateStr);
        return dateObj;
    } catch(Exception e) {
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)

表示日期的字符串

SimpleDateFormat对象返回的Date对象

java date date-format simpledateformat

0
推荐指数
1
解决办法
3090
查看次数