小编for*_*has的帖子

JDBCExceptionReporter [ERROR]字段'id'没有默认值

在尝试了不同的建议解决方案之后,我还没有弄清楚这一点.

我正在使用hibernate 3.6和mysql 5.x并试图保持我的实体(我排除了getter和setter):

@Entity
@Table(name = "brand_managers")
public class BrandManager implements Serializable {

    /** Serial version unique id */
    private static final long serialVersionUID = -7992146584570782015L;

    /*--- Members ---*/

    /** The unique, internal ID of the entity. */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private long id;

    /**
     * The creation time of this user
     */
    @Temporal(TemporalType.DATE)
    @Column(name = "creation_time")
    protected Calendar creationTime;

    /**
     * The hashed password
     */
    @Column(name = "password")
    protected String password;

    @Column(name = "first_name") …
Run Code Online (Sandbox Code Playgroud)

mysql persistence entity hibernate

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

Junit with Spring - TestContextManager [ERROR]允许TestExecutionListener捕获异常

在我的Spring-Maven - Tomcat web应用程序上的Hibernate-Mysql runnint中,我使用2种不同的Junit类别运行2种类型的Junit集成测试:

  1. LocalTests - 正在运行(不需要服务器),直接调用我的Web层方法(在这种情况下是运动衫).
  2. HttpTests - 模拟客户端并通过http请求调用我的Web层,需要tomcat启动并运行.

在每个测试课程上面我有:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:testApplicationContext.xml" })
Run Code Online (Sandbox Code Playgroud)

我的测试套件看起来像那样(这是2中的一个,每个类别都有一个):

@RunWith(Categories.class)
@IncludeCategory(HttpTest.class)
@SuiteClasses({ ...All My Test Classes... })
public class HttpSuiteITCase {

    // Excluded: NotificationTests, ImageHttpTests

    /**
     * Run once before any of the test methods.
     */
    @BeforeClass
    public static void setTestsConfigurations() {
    TestConfiguration.setup(false);
    }
Run Code Online (Sandbox Code Playgroud)

我的testApplicationContext实际上是空的,它只包含组件扫描:

<context:component-scan base-package="com.company.app" />
Run Code Online (Sandbox Code Playgroud)

当我运行本地测试时,一切运行顺利,但是当我调用mt HTTP测试时它会崩溃:

2012-07-22 17:56:13 DefaultListableBeanFactory [INFO] Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@2598a35d: defining beans [httpBrandManagerTestsProxy,httpClubTestsProxy,<HERE THERE'S A BUNCH OF SPRING BEANS>,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,contextApplicationContextProvider,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory …
Run Code Online (Sandbox Code Playgroud)

junit spring integration-testing tomcat maven

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

使用注释将属性注入到 spring bean

正如这里这里所解释的,很清楚如何做到这一点,但似乎仍然无法使其发挥作用。我只是喜欢使用 @Value 注释来将属性注入到 spring bean 中。我创建了一个基本的 spring MVC 项目,其中包含一个控制器和一个 bean。

这是我的应用程序上下文:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util" xmlns:beans="http://www.springframework.org/schema/beans"
    xsi:schemaLocation="
   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
   http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
   http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd
   http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd">


<!-- Root Context: defines shared resources visible to all other web components -->

<context:component-scan base-package="me.co.fatsecret" />

<!-- Properties -->

<bean id="props"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:fatProperties.properties" />
</bean>


</beans>
Run Code Online (Sandbox Code Playgroud)

我有一个名为配置的 bean:

package me.co.fatsecret;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class Configuration …
Run Code Online (Sandbox Code Playgroud)

spring spring-mvc

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

无法打开META-INF/persistence.xml,因为它不存在

我正在创建一个基本的spring-maven项目,它应该作为java应用程序运行(在进程中,而不是在Web服务器上).

我的应用程序上下文位于我的类路径中的resources文件夹下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:ox="http://www.springframework.org/schema/oxm"
    xsi:schemaLocation="
   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
   http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.1xsd">


<!-- Root Context: defines shared resources visible to all other web components -->

<!-- Context -->
<context:component-scan base-package="me.co.nutrition" />

<!-- Properties -->
<context:property-placeholder
    location="classpath:/nutrition.accumulation.properties" />

<!-- DB -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="${jdbc.driverClassName}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
</bean>

<bean id="persistenceUnitManager"
    class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
    <property name="defaultPersistenceUnitName" value="nutrition-pu"/>
    <property name="persistenceXmlLocation" …
Run Code Online (Sandbox Code Playgroud)

spring classpath persistence.xml applicationcontext

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