我试图在JavaEE项目中实现Json支持,但是生成了与MOXy相关的异常的问题.我在jersey.java.net上读到,MOXy应该是自动发现的,但是当我尝试时它似乎不起作用.
因此,为了简化这一点,我只是生成了一个新的' jersey-quickstart-webapp '项目并更改了MyResource,如下所示(我的目标是使用Application类而不是web.xml,但这是最简单的方法,可以找到它.无论发生什么错误都会发生.
@Path("myresource")
public class MyResource {
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getIt() {
return Response.status(Response.Status.ACCEPTED).entity(new TestEntity()).build();
}
}
Run Code Online (Sandbox Code Playgroud)
TestEntity类(在同一个包中):
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class TestEntity {
private String content = "SOME CONTENT";
public String getContent() {
return content;
}
}
Run Code Online (Sandbox Code Playgroud)
pom.xml中:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>a.b.c</groupId>
<artifactId>server</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>server</name>
<build>
<finalName>server</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies> …Run Code Online (Sandbox Code Playgroud) 我在寻找如何使用 XUnit 在 MS Test Runner(与 Resharper 测试运行器中相同)中根据类层次结构显示测试时遇到问题。
我的结构类似于下面的示例:
public class ManagerTests
{
public class Create
{
public class When_Something
{
[Fact]
public void Then_this_should_happen()
{
}
}
public class When_Something_else
{
[Fact]
public void Then_else_should_happen()
{
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我希望它显示为(在测试运行程序中):
ManagerTests
Create
When_something
Then_this_should_happen
When_something_else
Then_else_should_happen
Run Code Online (Sandbox Code Playgroud)
但我似乎最终得到的是:
ManagerTests+Create+When_something
Then_this_should_happen
ManagerTests+Create+When_something_else
Then_else_should_happen
Run Code Online (Sandbox Code Playgroud)
我查看了xunit 配置设置,但似乎没有找到任何调整此设置的方法。我尝试了不同的分组选项,但没有找到任何解决此问题的方法。发现一些较旧的帖子询问有关此问题的问题(如本帖子),但到目前为止我还没有找到如何做到这一点。
所以问题是:我怎样才能停止嵌套的类名串联(class1+class2+class3)并呈现它们的层次结构?
我在启用不可为空的引用类型时遇到了一些问题。不确定这是一个实际问题,还是我没有跟上最新的命名/设置。
这是我当前的设置(使用 VS Code):
dotnet 版本:3.0.100-preview6-012264 无所不能:1.20.0
我注意到启用 nullable 的标志已更改多次,但正如我在文档和互联网上看到的那样,最新的似乎是<Nullable/>我全部启用的(下面显示的主 Web 项目和我的 .NET Standard 2.0 类库中) ):
<Project Sdk="Microsoft.NET.Sdk.Web">
...
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<WarningsAsErrors>CS8600;CS8602;CS8603</WarningsAsErrors>
</PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
如果我#nullable enable在我正在测试的文件中使用,我会看到 IntelliSense 直接切换到正确的警报。在文件中添加它也会使构建失败(这是我正在寻找的行为)。
我在这里缺少什么才能在项目级别上工作?
我有问题让aufotac注入我的autopmapper typeconverters.我尝试了一些不同的方法,但我目前使用下面的代码.最接近IVE来找到一个解决方案是下面(从借用小位的码http://thoai-nguyen.blogspot.se/2011/10/autofac-automapper-custom-converter-di.html).他的样本似乎以1:1的方式工作,但还没能找到我失踪的东西.像往常一样提取相关位,让我知道它是否不足.
我的autofac bootstrapper:
public class AutoFacInitializer
{
public static void Initialize()
{
//Mvc
var MvcContainer = BuildMvcContainer();
DependencyResolver.SetResolver(new AutofacDependencyResolver(MvcContainer));
//Web API
var ApiContainer = BuildApiContainer();
var ApiResolver = new AutofacWebApiDependencyResolver(ApiContainer);
GlobalConfiguration.Configuration.DependencyResolver = ApiResolver;
}
private static IContainer BuildApiContainer()
{
var builder = new ContainerBuilder();
var assembly = Assembly.GetExecutingAssembly();
builder.RegisterApiControllers(assembly);
return BuildSharedDependencies(builder, assembly);
}
private static IContainer BuildMvcContainer()
{
var builder = new ContainerBuilder();
var assembly = typeof (MvcApplication).Assembly;
builder.RegisterControllers(assembly);
builder.RegisterFilterProvider();
return BuildSharedDependencies(builder, assembly);
}
private static IContainer …Run Code Online (Sandbox Code Playgroud)