小编Bet*_*sta的帖子

创建一个Spring枚举bean并传递方法调用的值

我有这个Singleton:

   public enum Elvis {
       INSTANCE;
       private int age;

       public int getAge() {
           return age;
       }
   }
Run Code Online (Sandbox Code Playgroud)

我知道如何在spring中创建枚举bean:

   <bean id="elvis" class="com.xyz.Elvis" factory-method="valueOf">
           <constructor-arg>
               <value>INSTANCE</value>
           </constructor-arg>
   </bean> 
Run Code Online (Sandbox Code Playgroud)

如何将INSTANCE.getAge()返回的int传递给另一个bean构造函数?

java enums spring

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

使用maven为eclipse编译器设置Java 6注释处理配置

为Java 6注释处理器设置eclipse项目编译器配置的最佳方法是什么?

我的解决方案是手动设置org.eclipse.jdt.apt.core.prefsfactorypath文件.这有点麻烦:

  • 引用factorypath文件中的处理器jar
  • 配置eclipse注释处理器输出目录(org.eclipse.jdt.apt.genSrcDir属性org.eclipse.jdt.apt.core.prefs)
  • 添加eclipse注释处理器输出目录作为源文件夹

一个问题是eclipse生成的源将使用maven编译.只有maven clean compile可靠,因为它删除了eclipse生成的源文件.(Eclipse和javac生成的源文件可能不同步.)

有没有更好的解决方案来配置maven没有eclipse生成的源文件在maven源路径?

<project>
  <properties>
    <eclipse.generated.src>${project.build.directory}/eclipse</eclipse.generated.src>
  </properties>
  <build>
      <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.4</version>
            <executions>
                <execution>
                  <id>add-source</id>
                  <phase>generate-sources</phase>
                  <goals> <goal>add-source</goal> </goals>
                  <configuration>
                      <sources>
                        <source>${eclipse.generated.src}</source>
                      </sources>
                    </configuration>
              </execution>
            </executions>
          </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-eclipse-plugin</artifactId>
        <configuration>
          <additionalConfig>
            <file> <name>.factorypath</name>
        <content><![CDATA[<factorypath>
  <factorypathentry kind="VARJAR" id="M2_REPO/processor/processor.jar" enabled="true" runInBatchMode="false"/>
  </factorypath>
  ]]>      </content>
            </file>
            <file>
              <name>.settings/org.eclipse.jdt.apt.core.prefs</name>
        <content><![CDATA[
  eclipse.preferences.version=1
  org.eclipse.jdt.apt.aptEnabled=true
  org.eclipse.jdt.apt.genSrcDir=${eclipse.generated.src}
  org.eclipse.jdt.apt.reconcileEnabled=true
   ]]>     </content>
            </file>
          </additionalConfig>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
Run Code Online (Sandbox Code Playgroud)

java eclipse maven-2 annotations javac

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

使用CXF Webservice进行服务器端XML验证

我正在开发Apache CXF Web服务(使用JAX-WS,通过SOAP).服务本身非常简单:接收请求,将请求插入数据库,并返回插入是否成功.我想依靠XML验证来对请求强制执行许多约束.

所以,我的问题.如何将详细的验证错误返回给我的服务客户?我通过配置我的端点在服务器端进行了验证.

<jaxws:endpoint id="someEndpoint" implementor="#someImpl" address="/impl">
    <jaxws:properties>
        <!-- This entry should- ideally- enable JAXB validation
        on the server-side of our web service. -->
        <entry key="schema-validation-enabled" value="true" />
    </jaxws:properties>
</jaxws:endpoint>
Run Code Online (Sandbox Code Playgroud)

我已经探索过在服务器上使用拦截器(例如BareInInterceptor),并以某种方式捕获SAXParseExceptions来包装它们并将它们发送到客户端.这种方法看起来有点复杂,但如果XML无效,我需要以某种方式为客户端提供一个行号.我应该使用拦截器来揭露异常吗?

我对这个技术堆栈并不是很有经验,只是进入Web服务 - 你们给我的任何指针都会非常感激.

web-services cxf jax-ws jaxb xml-validation

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

Spring框架:使用util:map填充Map <Enum,Object>

我有这个工厂类,我想通过spring连接到地图的运行时配置.该映射包含枚举对象和标准pojo.

public class GenericEntityFactoryImpl implements GenericEntityFactory
{
    private Map<IndexType,IEntity> indexEntityMap = null;

    @Override
    public IEntity getIndexEntity(IndexType index) {
        return indexEntityMap.get(index);
    }

    public Map<IndexType, IEntity> getIndexEntityMap() {
        return indexEntityMap;
    }

    public void setIndexEntityMap(Map<IndexType, IEntity> indexEntityMap) {
        this.indexEntityMap = indexEntityMap;
    }
}
Run Code Online (Sandbox Code Playgroud)

我在使用spring util时出现问题:地图布线,因为在确定键值时我不确定如何正确引用特定的枚举类型.地图值的bean ref很简单.弹簧图布线的所有例子似乎都假设键是一个字符串!

<!-- the value object bean -->
<bean id="cell" class="com.xx.xx.common.index.entity.CellEntity"/>

<bean id="genericEntityFactory" class="com.xx.xx.common.index.GenericEntityFactoryImpl">
  <util:map 
       id="indexEntityMap" 
       map-class="java.util.HashMap" 
       key-type="com.xx.xx.common.index.IndexType" 
       value-type="com.xx.xx.common.index.GenericEntityFactoryImpl">
           <entry key="CELL">
                <ref bean="cell"/>
            </entry>
       </util:map>
</bean> 
Run Code Online (Sandbox Code Playgroud)

编辑

所以我重构了映射

<bean id="genericEntityFactory" class="com.xx.xx.common.index.GenericEntityFactoryImpl" >
    <property name="indexEntityMap">
        <map >
            <entry key="com.xx.xx.common.index.CELL"><ref bean="cell"/></entry> …
Run Code Online (Sandbox Code Playgroud)

java spring

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

使用maven Build Helper Maven插件

我正在尝试使用maven插件将maven java项目的源文件夹添加到Eclipse.

尝试使用org.codehaus.mojo插件时,我收到以下错误

未能执行目标org.codehaus.mojo:建立辅助性Maven的插件:1.7:添加源(默认CLI)项目应用程序框架:参数"来源"为目标org.codehaus.mojo:建立辅助-maven-plugin:1.7:add-source缺失或无效 - > [帮助1]

通过阅读http://mojo.codehaus.org/build-helper-maven-plugin/usage.html上的文档,这应该是正确的吗?文件夹target/sources/mygeneratedfiles on存在.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <executions>
        <execution>
         <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>target/sources/mygeneratedfiles</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

maven m2e

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

如何使用Maven 3.x为findbugs生成html报告

有没有人设法配置findbugs Maven 3.x插件来生成xml和html报告?(我想要一个用于Jenkins的xml和一个用于在提交之前进行检查的html)

我见过很多文档设置此功能在网络上,但大部分似乎是Maven的2.x的,这是我知道的配置差异(烦人2.x的配置默默3.X忽略) .我是Maven的新手,所以我不确定我是做错了什么还是我遵循旧的指示.

我的pom包含以下内容:

</build>
    </plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>findbugs-maven-plugin</artifactId>
            <version>2.3.3</version>
            <configuration>
                <!-- findbugs:help -Ddetail=true  for outputDirectory:
                     Location where generated html will be created. 
                 -->
                <outputDirectory>${project.build.directory}/findbugs</outputDirectory>

                <xmlOutput>true</xmlOutput>
                <findbugsXmlWithMessages>true</findbugsXmlWithMessages>
                <xmlOutputDirectory>target/findbugs</xmlOutputDirectory>
                <failOnError>false</failOnError>
            </configuration>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

findbugs maven

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

Java SSO:针对Active Directory的Kerberos身份验证

我仍在尝试为SSO(在*nix上运行)找到基于Java的解决方案,我可以在JBoss上使用它来针对Active Directory /域控制器进行授权.我最初尝试通过NTLM执行此操作,但放弃了因为它在Windows Server> = 2008上不受支持.

因此,我正在尝试使用Kerberos实现此功能,但似乎无法找到正确/可行的解决方案.请指出正确的方向,说明如何设置这样的配置,如何验证Active Directory和/或域控制器,以便:

  1. 找出该帐户是否有效
  2. 获取用户的组列表

任何帮助表示赞赏!


UPDATE

我正在使用jcifs-ext-0.9.4和jcifs-krb5-1.3.12开发解决方案.我按如下所述设置了web.xml:

<web-app>
  <!-- servlet / servlet-mapping / welcome-file-list skipped -->

 <filter>
 <filter-name>auth</filter-name>
 <filter-class>jcifs.http.AuthenticationFilter</filter-class>

 <init-param>
 <param-name>java.security.auth.login.config</param-name>
 <param-value>/WEB-INF/login.conf</param-value>
 </init-param>

 <init-param>
 <param-name>jcifs.spnego.servicePrincipal</param-name>
 <param-value>HTTP/testconn@mydomain.com</param-value>
 </init-param>

 <init-param>
 <param-name>jcifs.spnego.servicePassword</param-name>
 <param-value>supersecret</param-value>
 </init-param>

 <init-param>
 <param-name>sun.security.krb5.debug</param-name>
 <param-value>true</param-value>
 </init-param>

 <init-param>
 <param-name>java.security.krb5.realm</param-name>
 <param-value>mydomain.com</param-value>
 </init-param>

 <init-param>
 <param-name>java.security.krb5.kdc</param-name>
 <param-value>testdom01.mydomain.com </param-value>
 </init-param>

 <init-param>
 <param-name>jcifs.smb.client.domain</param-name>
 <param-value>TESTDOMAIN</param-value>
 </init-param>

 <init-param>
 <param-name>jcifs.http.enableNegotiate</param-name>
 <param-value>true</param-value>
 </init-param>

 <init-param>
 <param-name>jcifs.http.basicRealm</param-name>
 <param-value>mydomain.com</param-value>
 </init-param>

 <init-param>
 <param-name>jcifs.http.domainController</param-name>
 <param-value>testdom01.mydomain.com</param-value>
 </init-param>

 </filter>
 <filter-mapping>
 <filter-name>auth</filter-name>
 <url-pattern>/*</url-pattern>
 </filter-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)

如果尝试访问应用程序,这会导致以下堆栈跟踪:

2010-07-22 15:53:10,588 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/google].[default]] Servlet.service() for servlet …
Run Code Online (Sandbox Code Playgroud)

java authentication kerberos active-directory single-sign-on

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

Spring的Json没有得到适当的回应

我试图让Spring中的控制器返回一个JSON响应无法使用3.0推荐的Jackson类.我当然在我的课程路径中获得了jackson jar文件(jackson-core-asl-1.5.5.jar和jackson-mapper-asl-1.5.5.jar).

至于appconfig.xml条目,我不确定我是否需要这些.在回到'时尚非json ajax'之前,我把它们放在那里作为最后的绝望行为.

在调试中,我看到控制器获取请求,返回foo然后,在firebug中,获得406.

错误消息如下:从记录器设置为debug时:org.springframework.web.HttpMediaTypeNotAcceptableException:找不到可接受的表示

根据响应:(406)该请求标识的资源仅能够根据请求"accept"headers()生成具有不可接受特性的响应.

我的appconfig.xml在这里:

    <!-- Configures support for @Controllers -->
    <mvc:annotation-driven />

    <!-- Resolves view names to protected .jsp resources within the /WEB-INF/views directory -->
    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
  <property name="mediaTypes">
    <map>
      <entry key="html" value="text/html"/>
      <entry key="json" value="application/json"/>
    </map>
  </property>
  <property name="viewResolvers">
    <list>
      <bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
      <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/"/>
        <property name="suffix" value=".jsp"/>
      </bean>
    </list>
  </property>
  <property name="defaultViews">
    <list>
      <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
    </list>
  </property>
</bean>
    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename" value="messages"></property>
    </bean>
Run Code Online (Sandbox Code Playgroud)

我的控制器

@RequestMapping(value="foo/bar", method=RequestMethod.GET)
public …
Run Code Online (Sandbox Code Playgroud)

java spring json spring-mvc jackson

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

@Async不适合我

我正在使用@Scheduled,它一直工作正常,但无法让@Async工作.我测试了很多次,似乎它使我的方法异步.我还缺少其他任何东西,配置或参数吗?我有一个有两个方法的类,一个用@Scheduled标记的方法,执行并调用第二个用@Async标记的方法.

这是我的配置:

<!-- Scans within the base package of the application for @Components to configure as beans -->
<context:component-scan base-package="com.socialmeety" />
<context:annotation-config />
<tx:annotation-driven transaction-manager="transactionManager" />
<task:annotation-driven/>

<!-- Configures support for @Controllers -->
<mvc:annotation-driven />

<!-- Resolves view names to protected .jsp resources within the /WEB-INF/views directory -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/"/>
    <property name="suffix" value=".jsp"/>
</bean>

<dwr:configuration />
<dwr:annotation-config />
<dwr:url-mapping />
<dwr:controller id="dwrController" debug="true" />

<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
Run Code Online (Sandbox Code Playgroud)

谢谢.

java spring

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

如何自定义Maven发布插件的标记格式?

在我们的SVN仓库中,我们存储这样的标签:

trunk
    project_a
    project_b
branches
    project_a
        branch_x
        branch_y
    project_b
tags
    project_a
        1.0
        1.1
    project_b
        1.0
Run Code Online (Sandbox Code Playgroud)

当我在项目A上运行Maven发布插件的" 准备 "目标时,默认情况下它会将标记创建为"tags/project_a-xx",这与我上面的标记命名方案不匹配.因此,我依赖于发布的任何人(即一个易犯错的人)来发现这一点并将标签更改为"tags/project_a/xx".如何告诉发布插件默认使用正确的格式?

"准备"目标有一个" 标签 "配置选项,声称这样做,但如果我设置如下:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-release-plugin</artifactId>
    <version>2.1</version>
    <configuration>
        <tag>${project.artifactId}/${project.version}</tag>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

...然后创建的标签是"tags/project_a/xx-SNAPSHOT",即它使用预发行版本号而不是发行版本号.将标签名称硬编码到POM中似乎也是错误的.

默认情况下,如何确保标记正确?

tagging default release maven maven-release-plugin

12
推荐指数
1
解决办法
8574
查看次数